<wctype.h> is the C standard header for wide-character classification and case mapping. It is the wide twin of ctype.h: isalpha → iswalpha, tolower → towlower. Use it on wchar_t / wint_t values from wchar.h, not on plain char bytes.
Remember
#include <wctype.h>
isw*(wc) → non-zero if true (not always 1)
tow*(wc) → mapped wchar, or unchanged
isalpha → iswalpha
isdigit → iswdigit
isspace → iswspace
tolower → towlower
toupper → towupper
argument type: wint_t (holds wchar_t or WEOF)
locale affects letter / space rules
Include it with wchar.h, pass wide characters, and test with if (iswdigit(wc))—not == 1.
Include <wctype.h> and usually <wchar.h> for I/O.
Work with wchar_t / wint_t (literals like L'A').
Call iswalpha, iswdigit, iswspace, or towlower / towupper.
Call setlocale from locale.h when locale-aware rules matter.
Piece
Required?
Role
#include <wctype.h>
Yes
Declares isw* / tow*
wint_t argument
Yes
Wide character or WEOF
setlocale
Often
Locale-aware letter / space rules
Pseudocode
Pseudocode
for each wchar_t wc in wide_string:
if iswdigit(wc):
handle digit
else if iswalpha(wc):
handle letter
mapped = towlower(wc) // or towupper
else if iswspace(wc):
skip / trim
else:
other (punct, …)
// truth test:
if iswalpha(wc): // non-zero means true
…
Reference
Cheat Sheet
Common classifiers and the ctype.h name map.
Function
True / result when
iswalpha(wc)
Alphabetic letter (locale rules)
iswdigit(wc)
Decimal digit L'0'–L'9'
iswalnum(wc)
Letter or digit
iswspace(wc)
Space, tab, newline, …
iswpunct(wc)
Punctuation
towlower(wc)
Lowercase mapping (or unchanged)
towupper(wc)
Uppercase mapping (or unchanged)
Narrow twin
is* / to* in ctype.h
Try it
Live Preview
Classify a wide character with the same categories as iswalpha, iswdigit, iswspace, and case maps (ASCII / C-locale style).
Browser simulation of common wctype.h checks (same idea as the C examples below).
Start at the beginning. The string begins with spaces and a tab.
Loop while space.iswspace is true for those characters, so p advances.
Stop at H. Letters are not whitespace.
Print from p. You see "Hello". Do not call narrow isspace on wchar_t.
Edge Cases & Pitfalls
Keep narrow and wide classification APIs separate.
mix
Do not use ctype on wchar_t
Call iswalpha, not isalpha, on wide characters.
truth
Non-zero means true
Write if (iswdigit(wc)), not if (iswdigit(wc) == 1).
locale
Locale changes letter rules
Accented letters may need setlocale before they count as iswalpha.
scope
Per character, not UTF-8 bytes
wctype.h classifies wide characters. Multibyte UTF-8 in char needs a different approach.
Analysis
Performance Notes
Approach
Cost
Best for
isw* / tow*
Usually a table lookup
Wide parsers and validators
Manual ASCII ranges
Similar speed, less portable
Only when you force ASCII-only
Scan a whole wide string
O(n) characters
Normal; I/O usually dominates
Prefer wctype.h for clarity and locale-correctness when you already work in wchar_t. Avoid converting to narrow just to call ctype.h.
Remember
Key Takeaways
Role: classify and case-map wide characters.
Pair: use with wchar.h; use ctype.h for char.
Truth: non-zero means true—do not compare to 1.
Locale:setlocale when letters beyond ASCII matter.
One line:wctype.h is ctype.h for wchar_t—classify and map one wide character at a time.
Frequently Asked Questions
wctype.h is the C standard header for classifying and converting wide characters. It provides iswalpha, iswdigit, iswspace, towlower, towupper, and related functions—the wide equivalents of ctype.h helpers like isalpha and tolower.
ctype.h works on narrow characters (char/int) from byte strings. wctype.h works on wide characters (wint_t/wchar_t). Use ctype.h with char*; use wctype.h with wchar_t* and wprintf.
wchar.h handles wide strings and I/O: wcslen, wcscpy, wprintf, mbstowcs. wctype.h tests and transforms single wide characters: iswalpha, towlower. Include both when you need string work plus classification.
wint_t can hold any wchar_t value plus WEOF. Classification functions take wint_t so they can accept wide characters and end-of-file from wide input functions.
Yes. Which characters count as letters, digits, or whitespace depends on the current locale. Call setlocale from locale.h when you need locale-aware rules for accented letters.
No. Use iswspace for wide characters. Mixing ctype.h functions with wchar_t values is incorrect—keep narrow APIs for char and wide APIs for wchar_t.