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);
}
Answer
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.
View answer
Workspace
Report Error
Discuss