Names specified for <ctype.h>, “Classification and transformation of single-byte characters”
Name Description Notes Source Availability
EOF End-of-stream indicator M Headers C89 C90 C95 C99 C11
isalnum() Test for alphanumeric character (·) <ctype.h> C89 C90 C95 C99 C11
isalpha() Test for alphabetic character (·) <ctype.h> C89 C90 C95 C99 C11
isblank() Test for blank character (·) <ctype.h> C99 C11
iscntrl() Test for control character (·) <ctype.h> C89 C90 C95 C99 C11
isdigit() Test for digit character (·) <ctype.h> C89 C90 C95 C99 C11
isgraph() Test for graphic character (·) <ctype.h> C89 C90 C95 C99 C11
islower() Test for lower-case character (·) <ctype.h> C89 C90 C95 C99 C11
isprint() Test for printing character (·) <ctype.h> C89 C90 C95 C99 C11
ispunct() Test for punctuation character (·) <ctype.h> C89 C90 C95 C99 C11
isspace() Test for whitespace character (·) <ctype.h> C89 C90 C95 C99 C11
isupper() Test for upper-case character (·) <ctype.h> C89 C90 C95 C99 C11
isxdigit() Test for hexadecimal-digit character (·) <ctype.h> C89 C90 C95 C99 C11
tolower() Convert to character to lower-case (·) <ctype.h> C89 C90 C95 C99 C11
toupper() Convert to character to upper-case (·) <ctype.h> C89 C90 C95 C99 C11

This header is available in C89, C90, C95, C99 and C11.

Names specified for <wctype.h>, “Classification and transformation of wide characters”
Name Description Notes Source Availability
iswalnum() Test for alphanumeric wide character (·) <wctype.h> C95 C99 C11
iswalpha() Test for alphabetic wide character (·) <wctype.h> C95 C99 C11
iswblank() Test for blank wide character (·) <wctype.h> C99 C11
iswcntrl() Test for control wide character (·) <wctype.h> C95 C99 C11
iswctype() Test for wide-character class (·) <wctype.h> C95 C99 C11
iswdigit() Test for digit wide character (·) <wctype.h> C95 C99 C11
iswgraph() Test for graphic wide character (·) <wctype.h> C95 C99 C11
iswlower() Test for lower-case wide character (·) <wctype.h> C95 C99 C11
iswprint() Test for printing wide character (·) <wctype.h> C95 C99 C11
iswpunct() Test for punctuation wide character (·) <wctype.h> C95 C99 C11
iswspace() Test for whitespace wide character (·) <wctype.h> C95 C99 C11
iswupper() Test for upper-case wide character (·) <wctype.h> C95 C99 C11
iswxdigit() Test for hexadecimal-digit wide character (·) <wctype.h> C95 C99 C11
towctrans() Convert according to mapping (·) <wctype.h> C95 C99 C11
towlower() Convert to wide character to lower-case (·) <wctype.h> C95 C99 C11
towupper() Convert to wide character to upper-case (·) <wctype.h> C95 C99 C11
WEOF End-of-stream indicator H M Headers C95 C99 C11
wctrans() Identify wide-character transformation (·) <wctype.h> C95 C99 C11
wctrans_t Wide-character mapping T <wctype.h> C95 C99 C11
wctype() Classify wide character (·) <wctype.h> C95 C99 C11
wctype_t Wide-character classification T <wctype.h> C95 C99 C11
wint_t Wide-character or error type H T Headers C95 C99 C11

This header is available in C95, C99 and C11.

The header <ctype.h> declares functions for single-byte characters, while <wctype.h> declares functions for wide characters, and appears from C95.

Character classification

Several functions are provided to test whether characters belong to certain sets or classifications, such as upper-case, letter, digit, etc.… These classifications depend on the LC_CTYPE locale category.

#include <ctype.h>
int isalpha(int c);
int islower(int c);
int isupper(int c);
int isdigit(int c);
int isxdigit(int c);
int isalnum(int c);
int isblank(int c);
int isspace(int c);
int iscntrl(int c);
int isgraph(int c);
int isprint(int c);
int ispunct(int c);
#include <wctype.h>
int iswalpha(wint_t c);
int iswlower(wint_t c);
int iswupper(wint_t c);
int iswdigit(wint_t c);
int iswxdigit(wint_t c);
int iswalnum(wint_t c);
int iswblank(wint_t c);
int iswspace(wint_t c);
int iswcntrl(wint_t c);
int iswgraph(wint_t c);
int iswprint(wint_t c);
int iswpunct(wint_t c);

Functions with names matching ^is[a-z] might be added to <ctype.h> or <wctype.h>.

Single-byte characters supplied as char should be converted to unsigned char before passing to the is… functions, e.g., isalnum((unsigned char) c). Functions like getchar return a character already in this form. The wide-character functions need no such conversion.

Each function returns non-zero if the supplied character c belongs to the set implied by the function's name:

Character classifications
Name Description Definition Examples in the C locale
upper upper-case letters U+0041 through U+005A, plus locale-specific && !isdigit(c) && !ispunct(c) && !isspace(c) && !iscntrl(c) "ABCDEFGHIJKLM" "NOPQRSTUVWXYZ"
lower lower-case letters U+0061 through U+007A, plus locale-specific && !isdigit(c) && !ispunct(c) && !isspace(c) && !iscntrl(c) "abcdefghijklm" "nopqrstuvwxyz"
alpha letters islower(c) || isupper(c) || (locale-specific && !isdigit(c) && !ispunct(c) && !isspace(c) && !iscntrl(c))
digit base-10 digits U+0030 through U+0039 "0123456789"
xdigit base-16 digits U+0030 through U+0039, U+0041 through U+0046, U+0031 through U+0036 "0123456789" "abcdef" "ABCDEF"
alnum letters and digits isalpha(c) || isdigit(c) "0123456789" "abcdefghijklm" "nopqrstuvwxyz" "ABCDEFGHIJKLM" "NOPQRSTUVWXYZ"
punct punctuation characters (locale-specific && !isspace(c) && !isalnum(c)) "!\"#%&'()*+,-./:;" "<=>?[\]^_{|}~"
print printing characters
cntrl control characters
graph graphic characters isprint(c) && c != ' '
space whitespace characters (locale-specific && !isalnum(c)) " \f\n\r\t\v"
blank blank characters (locale-specific word separators within a line && isspace(c)) " \t" (U+0020 and U+0009)

For wide characters, it is possible to represent these categories textually:

#include <wctype.h>
wctype_t wctype(const char *prop);
int iswctype(wint_t c, wctype_t prop);

For example, iswctype(c, wctype("xdigit")) has the same behaviour as iswxdigit(c). If the string prop is not recognized, wctype returns zero, identifying a class that no character belongs to.

Depending on the LC_CTYPE category of the current locale, additional classifications may be recognized. Also, the locale is recorded in the wctype_t value, so even if LC_CTYPE is changed between the calls to wctype and iswctype, the second call works as if the old setting applies.

[ Work in progress : Looks like wctype(NULL) also returns zero.]

Character transformation

Six functions allow letters to be converted to upper- or lower-case according to the current LC_CTYPE locale category. They return the converted character if the original can be converted, or the original character if not:

#include <ctype.h>
int tolower(int c);
int toupper(int c);
#include <wctype.h>
wint_t towlower(wint_t c);
wint_t towupper(wint_t c);

Functions with names matching ^to[a-z] might be added to <ctype.h> or <wctype.h>.

Single-byte characters supplied as char should first be converted to unsigned char before passing to the to… functions, e.g., tolower((unsigned char) c). Functions like getchar return a character already in this form. The wide-character functions need no such conversion.

For wide characters, it is possible to represent these tranformations textually:

#include <wctype.h>
wctrans_t wctrans(const char *prop);
int towctrans(wint_t c, wctrans_t prop);

For example, towctrans(c, wctrans("toupper")) has the same behaviour as towupper(c). If the string prop is not recognized, wctrans returns zero, identifying an identity transformation.

Depending on the LC_CTYPE category of the current locale, additional transformations may be recognized. Also, the locale is recorded in the wctrans_t value, so even if LC_CTYPE is changed between the calls to wctrans and towctrans, the second call works as if the old setting applies.

[ Work in progress : Looks like wctrans(NULL) also returns zero.]

CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000