Step Into C · Lesson 20 · Systems C
Files & I/O
FILE *, fopen modes, error handling, reading lines, parsing, and binary files.
- ~40 minreading and coding
- 5missions
- membersaccess
- Clanguage
Part of Step Into C. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.
Reading configuration, parsing a log, loading a binary blob: sooner or later every program touches files. The C standard library gives you streams, represented by a FILE *. You already used three of them without opening anything: stdin, stdout and stderr.
In this lesson
- Files are streams of bytes
- Opening and closing
- Reading lines
- Writing
- Parsing text with sscanf
- Text mode vs binary mode
- Binary I/O: fread and fwrite
- Moving around: fseek and ftell
Missions
- Read a file line by line
- When opening fails
- Parse a CSV
- Write, then read back
- Binary records