Count Characters, Words, and Lines in a File in C

Counting the characters in a file is the “hello world” of C file handling — but done properly it teaches four things at once: the fgetc() read loop, why ch must be an int and not a char, the <ctype.h> classification functions, and word counting with a state flag. This version is a miniature wc: …