Files and reliable programs

Keeping data after a program ends, and recognising the mistakes that C will let you make.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Reading and writing files Intermediate

    Keep data after a program ends: open files with fopen, write with fprintf, read with fscanf and fgets, and handle a file that cannot be opened.

  2. 2

    Bugs C will not catch Intermediate

    Undefined behaviour: what real C does silently, and how to spot each bug before it bites.

Module practice

Module quiz

1. What should you do straight after calling fopen?
2. Which fopen mode adds to a file without erasing it?
3. A program prints the right answer. Can it still have undefined behaviour?
4. What does the -Wall option do?
5. Which is the right loop for reading integers until a file ends?

‹ Structures and dynamic memoryFinal assessment ›