A character class groups characters by a property such as alphabetic, numeric, whitespace, punctuation, or control status. C exposes common classes through <ctype.h>, avoiding assumptions about the execution character encoding. Its classifiers include isalpha, isdigit, isspace, isalnum, isupper, islower, isprint, isgraph, ispunct, and isxdigit; toupper and tolower convert alphabetic case while leaving other characters unchanged. section 8.4
Classifying digits and letters
A base-conversion helper can test a character with isdigit(a), subtract '0' for decimal digits, then apply toupper(a) and isupper(a) before mapping Latin letters to values. The surrounding code receives and returns int, because these historical interfaces use int rather than char. Decimal digits are consecutive and isdigit is not locale dependent; broader alphabetic classes may be extended by the implementation. section 8.4
Common classifications include:
- isspace recognizes space, form feed, newline, carriage return, tab, and vertical tab; isblank recognizes space and tab. section 8.4
- isdigit recognizes decimal digits, while isxdigit recognizes decimal and hexadecimal digits; these classes are not extended by the implementation. section 8.4
- isalnum combines alphabetic and decimal-digit membership; isalpha combines lowercase and uppercase membership. section 8.4
- scanf uses bracket expressions as input classes: %[aeiouAEIOU] accepts vowels, while %[^\n]%*[\n] reads a nonempty line and discards its newline. section 14.2
Table 8.11. Character classifiers The third column indicates whether C implementations may extend these classes with platform-specific characters, such as 'ä' as a lowercase character or '€' as punctuation. (view table figure)
| Name |
Meaning |
C locale |
Extended |
|---|---|---|---|
| islower | Lowercase | 'a' ... 'z' | Yes |
| isupper | Uppercase | 'A' ... 'Z' | Yes |
| isblank | Blank | ' ', '\t' | Yes |
| isspace | Space | ' ', '\f', '\n', '\r', '\t', '\v' | Yes |
| isdigit | Decimal | '0' ... '9' | No |
| isxdigit | Hexadecimal | '0' ... '9', 'a' ... 'f', 'A' ... 'F' | No |
| iscntrl | Control | '\a', '\b', '\f', '\n', '\r', '\t', '\v' | Yes |
| isalnum | Alphanumeric | isalpha(x)||isdigit(x) | Yes |
| isalpha | Alphabet | islower(x)||isupper(x) | Yes |
| isgraph | Graphical | (!iscntrl(x)) && (x != ' ') | Yes |
| isprint | Printable | !iscntrl(x) | Yes |
| ispunct | Punctuation | isprint(x)&&!(isalnum(x)||isspace(x)) | Yes |
Compare each classifier's meaning, C-locale members, and whether implementations may extend the class with platform-specific characters. section 8.4








