basics · intermediate · ~15 min
Track transitions between two states while scanning.
Implement int count_words(const char *s) returning the number of whitespace-separated words. Use a small in-word/out-of-word state machine.
int count_words(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.