FILE *f = fopen( fileName, "r" );
readData( f );
if( ???? )
{
puts( "End of file was reached" );
}
Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?
-
f == EOF
-
feof( f )
-
eof( f )
-
f == NULL
-
!f
B
Correct answer
Explanation
In standard C input/output library operations, feof(f) is the correct function used to check whether the end-of-file indicator has been set for the given file stream. EOF is an integer macro value returned by reading functions rather than a stream condition check macro.