A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
isspace returns nonzero for whitespace characters: space, tab, newline, carriage return, form feed, and vertical tab. In the C locale, that is exactly six characters. It is the function you use to skip leading whitespace, to split tokens, and to detect line boundaries. It is more robust than checking c == ' ' because it handles tabs and newlines without extra conditions.
#include <stdio.h>#include <ctype.h>const char *skip_whitespace(const char *s) {while (isspace((unsigned char)*s)) {s++;}return s;}int count_words(const char *s) {int count = 0;int in_word = 0;for (const char *p = s; *p; p++) {if (isspace((unsigned char)*p)) {in_word = 0;} else if (!in_word) {in_word = 1;count++;}}return count;}int main(void) {const char *padded = " \t Hello, World! \n";printf("After skip: \"%s\"\n", skip_whitespace(padded));const char *text = " one two three\tfour\n";printf("Word count: %d\n", count_words(text));return 0;}
The skip function advances past spaces, tabs, and newlines in one loop. The word counter uses isspace to detect boundaries between words. Multiple consecutive whitespace characters count as a single separator. The tab between "three" and "four" is handled correctly because isspace recognizes it. A manual c == ' ' check would have missed it.
isspace is the whitespace gatekeeper. Use it instead of manual space checks. It handles all six whitespace characters in one call and adapts to locale settings. Next: a small but important trick, printing the percent character with printf.
Finish the lesson once you have worked through the material. This awards ★ 10 XP.