typestar

Files & I/O

12 steps in 4 sets of C.

stdio, properly. Opening and reading, writing text and binary, then seeking and the stream behavior that explains why your output appears in the wrong order when you mix printf with write.

Twelve steps, and the buffering set is the one that pays for itself. Line-buffered to a terminal and block-buffered to a pipe is the reason a program's output looks fine interactively and arrives in the wrong order when redirected to a file. Unglamorous, and needed constantly.

Start this tour

Opening & reading

Writing & binary

Positioning & streams

Encore

  • wc_clone.cA word-count clone: read named files or stdin, count lines, words and bytes.

The other C tours