Multiple choice

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?

  1. f == EOF

  2. feof( f )

  3. eof( f )

  4. f == NULL

  5. !f

Reveal answer Fill a bubble to check yourself
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.