Q:
Point out the error, if any, in the following program.
# include "stdio.h"
main()
{
FILE *fp;
char str[80];
fp = fopen ("trail", "r");
while (!feof (fp))
{
fgets (str, 80, fp);
puts (str);
}
fclose (fp);
}
Answer
The last line from the file "trial" would be read twice. To avoid this, ues:
While ( fgets (str, 80, fp) ! = NULL)
puts (str);
View answer
Workspace
Report Error
Discuss