h-wctype
Table of Contents
<wctype.h>
<wctype.h> provides wide-character classification (iswalpha, iswdigit, iswspace) and case conversion (towupper, towlower). These functions work on full Unicode via wchar_t, unlike <ctype.h> which handles only ASCII.
Results depend on locale; call setlocale(LC_ALL, "") for correct Unicode support.
Example
This example classifies and case-converts wide characters in a string.
// compile: gcc -o wctypeexample wctypeexample.c // run: ./wctypeexample // description: classify and case-convert wide characters #include <wctype.h> #include <wchar.h> #include <locale.h> int main() { setlocale(LC_ALL, ""); const wchar_t* s = L"héLLo 42!"; for (const wchar_t* p = s; *p; p++) { wprintf(L"'%lc' alpha=%d digit=%d upper=%d upper→%lc\n", *p, iswalpha(*p) != 0, iswdigit(*p) != 0, iswupper(*p) != 0, towupper(*p)); } return 0; }
Common functions
Character classification (return non-zero if true):
iswalpha(c): letteriswdigit(c): decimal digitiswalnum(c): alphanumericiswspace(c): whitespaceiswpunct(c): punctuationiswprint(c): printableiswcntrl(c): control characteriswupper(c): uppercaseiswlower(c): lowercaseiswxdigit(c): hex digit
Case conversion:
towupper(c): convert to uppercasetowlower(c): convert to lowercasetowctrans(c, trans): apply locale-specific transform
Locale-specific classification:
wctype(name): get character class by nameiswctype(c, type): test membership in class
h-wctype.md · Last modified: by 127.0.0.1
