Get Started
822

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); }

  • Show Answer
  • Workspace

Answer :
Explanation :

The last line from the file "trial" would be read twice. To avoid this, ues:        While ( fgets (str, 80, fp) ! = NULL)                puts (str);

The Most Comprehensive Exam Preparation Platform

Get the Examsbook Prep App Today