Get Started
878

Q: Point out the error, if any, in the following program. #include "stdio.h" main() {       unsigned char;        FILE *fp;        fp = fopen ("trail", "r");        while (( ch = getc (fp)) ! = EOF)                printf ("%c", ch);        fclose (fp); }

  • Show Answer
  • Workspace

Answer :
Explanation :

EOF has been defined as #define EOF -1 n the file "stdio.h" and an unsigned char ranges from 0 to 255 hence when EOF is read from the file it cannot be accommodated in ch. Solution is to declare ch as an int.

The Most Comprehensive Exam Preparation Platform

Get the Examsbook Prep App Today