wc
A command-line program that counts the bytes, lines, words and characters in a file, or in whatever is piped into it, and matches the Unix wc tool. It is small to write, but getting every count right forces you to understand how text is really stored and how a program reads input it can't hold all at once.
You'll learn text encoding, streaming in constant memory, counting words with a state machine