Systems & CLI · Beginner
wc: Build a Word Count Tool
Build a command-line tool that counts the bytes, characters, words, and lines of a file or piped input, mirroring the behavior and flags of Unix wc.
This project recreates the classic Unix wc utility: a small program that reports how many bytes, characters, words, and lines a piece of text contains. You parse the -c, -l, -w, and -m flags, read from either a named file or standard input, and default to printing line, word, and byte counts when no flag is given. It is worth building because it teaches the Unix philosophy of composable text filters while giving concrete practice with argument parsing, buffered I/O, byte-versus-character encoding, and reading from stdin. It is the canonical first systems project: tiny in scope, but it forces you to handle real edge cases like multibyte UTF-8 characters and empty input.
What you build
- Counts lines, words, bytes, and characters for a given file
- Supports the -c (bytes), -l (lines), -w (words), and -m (characters) flags
- Defaults to printing lines, words, and bytes when no flag is provided
- Reads from standard input when no filename is given, enabling pipes
- Correctly counts multibyte UTF-8 characters distinctly from raw bytes
- Prints the filename alongside the counts, matching coreutils output format
- Handles multiple files and prints a total line
What it teaches
- Parsing command-line flags and arguments by hand
- Reading from both files and standard input for composable Unix tools
- The difference between bytes and characters in UTF-8 encoded text
- Buffered and streaming I/O patterns
- Matching an existing tool's exact output format for verification
Sign in to open the build guide
Free account. Get the step-by-step build and every resource link.
Take it further
- Add a -L flag that reports the length of the longest line.
- Support reading and totaling counts across many files passed at once.
- Stream input in fixed-size chunks instead of loading the whole file, so it works on huge inputs.


