Brainlag
  1. C
  2. Advanced
23/38 lessons

Reading and writing files

35 min5 exercisesPremium

Open files with fopen, read them with fgets and fscanf, write with fprintf, check for NULL and know why fclose matters, all in C.

The skill
Read and write files safely: check that they opened, read them line by line or field by field, and close them.
You make
A results summary, a report written and read back, and a high score file that keeps every run.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 22 Pointers to pointers. Free to try: C Foundations and the playground.

Step 1 of 9
exercise_1.c

You've reached the good stuff.

5 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

C, 32-bit: int and pointers are 4 bytes