Join Examsbook
851 0

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 AnswerHide 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.

Are you sure

  Report Error

Please Enter Message
Error Reported Successfully