Learn C Programming

Lesson 4 of 9 · Files

Module 13 · Files

Binary Files, fread and fwrite

Free with an accountReading

Kenji's racing game saves his best lap: 83.456789 seconds. He wants a small save file, so he writes the time with %.2f, the way lesson 3 wrote numbers. The next day the game loads 83.46. His record got slower overnight, without a single lap.

Checking what this lesson needs for you…

What is inside Binary Files, fread and fwrite

  1. Text rounds the number, bytes keep it
  2. fwrite and fread copy bytes
  3. The counts they return
  4. fseek and ftell: the file position
  5. A record by its index
  6. A binary file is not portable
  7. Text or binary: how to choose