C Standard Library

C <wctype.h> - wctype() Function



The C <wctype.h> wctype() function returns a value of type wctype_t that corresponds to the character category specified by property.

The value returned by this function depends on the LC_CTYPE category selected. A specific locale can accept multiple categories in which to classify its characters.

Syntax

wctype_t wctype (const char* property); 

Parameters

property

Specify a C string holding the name of the desired category. The values of property supported in all C locales are as follows:

Value of propertyDescription
"alnum" alphanumerical character iswalnum()
"alpha" letter character iswalpha()
"blank" blank character iswblank() (C99)
"cntrl" control character iswcntrl()
"digit" decimal digit character iswdigit()
"graph" character with graphical representation iswgraph()
"lower" lowercase letter character iswlower()
"print" printable character iswprint()
"punct" punctuation character iswpunct()
"space" white-space character iswspace()
"upper" uppercase letter character iswupper()
"xdigit" hexadecimal digit character iswxdigit()

Return Value

Returns a value of type wctype_t identifying a specific character category. This value is locale-dependent. Returns zero if property does not name a category supported by the current C locale.

Example:

The example below shows the usage of wctype() function.

#include <stdio.h>
#include <wchar.h>
#include <wctype.h>
 
int main (){
  int i = 0;
  wchar_t str[50] = L"99HEllo@";
  wchar_t c;

  //displaying the alphabetic 
  //character in upper case
  wctype_t check = wctype("alpha");
  wctrans_t trans = wctrans("toupper");
  while (str[i]) {
    c = str[i];
    if (iswctype(c, check)) {
      c = towctrans(c, trans);
      putwchar (c);      
    }
    i++;
  }
  return 0;
}

The output of the above code will be:

HELLO

❮ C <wctype.h> Library