Site Tools


wiki: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;
}
wiki/h-wctype.md · Last modified: by 127.0.0.1