VMS Help  —  CRTL  wctype
    Used for defining a character class. The value returned by this
    function is used in calls to the iswctype function.

    Format

      #include  <wctype.h> (ISO C)

      #include  <wchar.h> (XPG4)

      wctype_t wctype  (const char *char_class);

1  –  Argument

 char_class

    A pointer to a valid character class name.

2  –  Description

    The wctype function converts a valid character class defined for
    the current locale to an object of type wctype_t. The following
    character class names are defined for all locales:

    alnum        cntrl        lower        space
    alpha        digit        print        upper
    blank        graph        punct        xdigit

    Additional character class names may also be defined in the LC_
    CTYPE category of the current locale.

    See also iswctype.

3  –  Return Values

    x                  An object of type wctype_t that can be used in
                       calls to the iswctype function.
    0                  If the character class name is not valid for
                       the current locale.

4  –  Example

 #include <locale.h>
 #include <wchar.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>

  /* This test will set up a number of character class using wctype() */
  /* and then verify whether calls to iswctype() using these classes  */
  /* produce the same results as calls to the is**** routines.        */

 main()
 {

     wchar_t w_char;
     wctype_t ret_val;

     char *character = "A";

     /* Convert character to wide character format - w_char */

     if (mbtowc(&w_char, character, 1) == -1) {
         perror("mbtowc");
         exit(EXIT_FAILURE);
     }

     /* Check if results from iswalnum() matches check on */
     /* alnum character class                             */

     if ((iswalnum((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("alnum"))))
         printf("[%C] is a member of the character class alnum\n", w_char);
  else
     printf("[%C] is not a member of the character class alnum\n", w_char);

     /* Check if results from iswalpha() matches check on */
     /* alpha character class                             */

     if ((iswalpha((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("alpha"))))
    printf("[%C] is a member of the character class alpha\n", w_char);
     else
    printf("[%C] is not a member of the character class alpha\n", w_char);

     /* Check if results from iswcntrl() matches check on */
     /* cntrl character class                             */

     if ((iswcntrl((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("cntrl"))))
     printf("[%C] is a member of the character class cntrl\n", w_char);
     else
    printf("[%C] is not a member of the character class cntrl\n", w_char);

     /* Check if results from iswdigit() matches check on */
     /* digit character class                             */

     if ((iswdigit((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("digit"))))
     printf("[%C] is a member of the character class digit\n", w_char);
     else
    printf("[%C] is not a member of the character class digit\n", w_char);

     /* Check if results from iswgraph() matches check on */
     /* graph character class                             */

     if ((iswgraph((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("graph"))))
         printf("[%C] is a member of the character class graph\n", w_char);
     else
    printf("[%C] is not a member of the character class graph\n", w_char);

     /* Check if results from iswlower() matches check on */
     /* lower character class                             */

     if ((iswlower((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("lower"))))
         printf("[%C] is a member of the character class lower\n", w_char);
     else
    printf("[%C] is not a member of the character class lower\n", w_char);

     /* Check if results from iswprint() matches check on */
     /* print character class                             */

     if ((iswprint((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("print"))))
         printf("[%C] is a member of the character class print\n", w_char);
     else
    printf("[%C] is not a member of the character class print\n", w_char);

     /* Check if results from iswpunct() matches check on */
     /* punct character class                             */

     if ((iswpunct((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("punct"))))
         printf("[%C] is a member of the character class punct\n", w_char);
     else
    printf("[%C] is not a member of the character class punct\n", w_char);

     /* Check if results from iswspace() matches check on */
     /* space character class                             */

     if ((iswspace((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("space"))))
         printf("[%C] is a member of the character class space\n", w_char);
     else
     printf("[%C] is not a member of the character class space\n", w_char);

     /* Check if results from iswupper() matches check on */
     /* upper character class                             */

     if ((iswupper((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("upper"))))
         printf("[%C] is a member of the character class upper\n", w_char);
     else
     printf("[%C] is not a member of the character class upper\n", w_char);

     /* Check if results from iswxdigit() matches check on */
     /* xdigit character class                             */

     if ((iswxdigit((wint_t) w_char)) &&
         (iswctype((wint_t) w_char, wctype("xdigit"))))
         printf("[%C] is a member of the character class xdigit\n", w_char);
     else
    printf("[%C] is not a member of the character class xdigit\n", w_char);

 }

    Running this example produces the following result:

    [A] is a member of the character class alnum
    [A] is a member of the character class alpha
    [A] is not a member of the character class cntrl
    [A] is not a member of the character class digit
    [A] is a member of the character class graph
    [A] is not a member of the character class lower
    [A] is a member of the character class print
    [A] is not a member of the character class punct
    [A] is not a member of the character class space
    [A] is a member of the character class upper
    [A] is a member of the character class xdigit
Close Help