CodePudding user response:
To evaluate the fgets return value, when they read the EOF returns NULL, then it is good to break out of the loop ~CodePudding user response:
Judge the return value first, then print, while judging feof againCodePudding user response:
Change, so look at the line not line?# include & lt; stdio.h>
Int main (void)
{
FILE *fp;
Char buf [BUFSIZ];
If ((fp=fopen (__FILE__, "r"))==NULL)
{
Perror (" fopen ");
return 1;
}
while(! The feof (fp) & amp; & The fgets (buf, BUFSIZ, fp))
{
Printf (" % s ", buf);
}
return 0;
}