Question 8
Back to Exercise
When does feof(fp) return a non-zero value?
- A As soon as the last byte has been read
- B After a read operation has tried to go past the end of the file Correct
- C When the file is empty, before any read
- D After fclose()
Correct Answer: Option B
The end-of-file indicator is set by a read that fails. That is why while (!feof(fp)) runs one extra time; test the read function's result instead.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!