A character class is a set of characters sharing a property, such as alphabetic, numeric, whitespace, or punctuation. C exposes common classes through <ctype.h> classifier functions, while character and string literals remain usable across platform encodings. section 8.5
Table 8.14 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.
| Name | Meaning | C locale | Extended |
islower |
Lowercase | ’a’ ⋯ ’z’ |
Yes |
isupper |
Uppercase | ’A’ ⋯ ’Z’ |
Yes |
isblank |
Blank | ’ ’, ’'͡ |
Yes |
isspace |
Space | ”, ’'̑, ’’, ’'̊, ’'͡, ’'̌ |
Yes |
isdigit |
Decimal | ’0’ ⋯ ’9’ |
No |
isxdigit |
Hexadecimal | ’0’ ⋯ ’9’, ’a’ ⋯ ’f’, ’A’ ⋯ ’F’ |
No |
iscntrl |
Control | ’’, ’'̱, ’'̑, ’’, ’'̊, ’'͡, ’'̌ |
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 |
The classifier table connects each predicate to its C-locale meaning and shows which classes implementations may extend with platform-specific characters. section 8.5
Use the classifiers and conversions according to these distinctions:
- Use isalpha, isdigit, isalnum, islower, and isupper for alphabetic and numeric categories; use isspace and isblank for whitespace-related tests. section 8.5
- Use isxdigit for hexadecimal digits; unlike several alphabetic classes, decimal and hexadecimal digit classes are not locale-extended. section 8.5
- Use isgraph, isprint, ispunct, and iscntrl to distinguish graphical, printable, punctuation, and control characters. section 8.5
- Remember that the classifiers and toupper/tolower take and return int for historical reasons; the case conversions leave nonalphabetic characters unchanged. section 8.5
Character classes in formatted input
A scanf scan set selects a class explicitly: "%[aeiouAEIOU]" matches vowels. Beginning the set with ^ negates it, so "%[^\n]%*[\n]" reads a nonempty line and discards its final newline. section 14.2
Character classes also support conversion logic. A hexadecimal-style converter can test isdigit, subtract '0' for consecutive decimal digits, convert with toupper, and then test isupper for alphabetic digits.








