The C standard header <ctype.h> provides classifiers for common character classes and the case-conversion functions toupper and tolower. These interfaces work with character classes without depending directly on a particular encoding. For historical reasons, the classifiers and conversions take int arguments and return int. section 8.5
Converting a digit or alphabetic digit
unsigned hexatridecimal(int a) { if (isdigit(a)) return a - '0'; a = toupper(a); return isupper(a) ? 10 + (a - 'A') : -1; } Here isdigit recognizes decimal digits, whose character codes are guaranteed to be consecutive. toupper normalizes alphabetic input before isupper tests it. section 8.5
The classifiers cover these commonly used character classes:
- isalnum, isalpha, islower, and isupper classify alphanumeric, alphabetic, lowercase, and uppercase characters. section 8.5
- isdigit and isxdigit recognize decimal and hexadecimal digits; their C-locale classes are not extended with platform-specific characters. section 8.5
- isblank, isspace, iscntrl, isgraph, isprint, and ispunct classify whitespace, control, graphical, printable, and punctuation characters. section 8.5
- toupper and tolower convert alphabetic characters and leave other characters unchanged. 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 |
Use the classifier table to compare each predicate's meaning, C-locale members, and possible platform-specific extensions. section 8.5
Character literals such as 'a' and '\n' have type int, and numeric octal or hexadecimal character escapes require care because hexadecimal escapes consume every following hexadecimal digit that belongs to the code. section 8.5

