Learn C Programming

Lesson 5 of 9 · Files

Module 13 · Files

EOF, Errors, and Closing What You Opened

Free with an accountReading

Bob writes a small tool that prints Maria's sales file on the screen. The file has three lines. The screen shows four: the last sale appears twice.

Sign in to read

This lesson is free, with an account

An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.

What is inside EOF, Errors, and Closing What You Opened

  1. Bob's loop prints the last line twice
  2. Test the read, not feof
  3. After the loop: the end, or an error?
  4. fclose can fail, so check what it returns
  5. A written line waits in a buffer
  6. How a program ends decides what is saved