Example (iswtype -- Test for Character Property)

The following shows calls to wctype and indicates the equivalent isw* function:

iswctype(wc, wctype("alnum"));   /* iswalnum(wc);  */
iswctype(wc, wctype("alpha"));   /* iswalpha(wc);  */
iswctype(wc, wctype("blank"));   /* iswblank(wc);  */
iswctype(wc, wctype("cntrl"));   /* iswcntrl(wc);  */
iswctype(wc, wctype("digit"));   /* iswdigit(wc);  */
iswctype(wc, wctype("graph"));   /* iswgraph(wc);  */
iswctype(wc, wctype("lower"));   /* iswlower(wc);  */
iswctype(wc, wctype("print"));   /* iswprint(wc);  */
iswctype(wc, wctype("punct"));   /* iswpunct(wc);  */
iswctype(wc, wctype("space"));   /* iswspace(wc);  */
iswctype(wc, wctype("upper"));   /* iswupper(wc);  */
iswctype(wc, wctype("xdigit"));  /* iswxdigit(wc); */

This example analyzes all characters between 0x0 and 0xFF. The output of this example is a 256-line table showing the characters from 0 to 255, indicating whether they have the properties tested for.

#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <wctype.h>
#define UPPER_LIMIT   0xFF
#if (1 == __TOS_OS2__)
   #define LOCNAME "en_us.ibm-437"       /* OS/2 name */
#else
   #define LOCNAME "en_us.ibm-1252"   /* Windows name */
#endif
int main(void)
{
   wint_t wc;
   if (NULL == setlocale(LC_ALL, LOCNAME)) {
      printf("Locale \"%s\" could not be loaded\n", LOCNAME);
      exit(1);
   }
   for (wc = 0; wc <= UPPER_LIMIT; wc++) {
      printf("%#4x ", wc);
      printf("%c", iswctype(wc, wctype("print"))  ? wc    : ' ');
      printf("%s", iswctype(wc, wctype("alnum"))  ? " AN" : "   ");
      printf("%s", iswctype(wc, wctype("alpha"))  ? " A " : "   ");
      printf("%s", iswctype(wc, wctype("blank"))  ? " B " : "   ");
      printf("%s", iswctype(wc, wctype("cntrl"))  ? " C " : "   ");
      printf("%s", iswctype(wc, wctype("digit"))  ? " D " : "   ");
      printf("%s", iswctype(wc, wctype("graph"))  ? " G " : "   ");
      printf("%s", iswctype(wc, wctype("lower"))  ? " L " : "   ");
      printf("%s", iswctype(wc, wctype("punct"))  ? " PU" : "   ");
      printf("%s", iswctype(wc, wctype("space"))  ? " S " : "   ");
      printf("%s", iswctype(wc, wctype("print"))  ? " PR" : "   ");
      printf("%s", iswctype(wc, wctype("upper"))  ? " U " : "   ");
      printf("%s", iswctype(wc, wctype("xdigit")) ? " H " : "   ");
      putchar('\n');
   }
   return 0;
   /**************************************************************
      The output should be similar to :
         .
         .
      0x1e            C
      0x1f            C
      0x20         B                 S  PR
      0x21 !                G     PU    PR
      0x22 "                G     PU    PR
      0x23 #                G     PU    PR
      0x24 $                G     PU    PR
      0x25 %                G     PU    PR
         .
         .
      0x30 0 AN          D  G           PR    H
      0x31 1 AN          D  G           PR    H
      0x32 2 AN          D  G           PR    H
      0x33 3 AN          D  G           PR    H
      0x34 4 AN          D  G           PR    H
      0x35 5 AN          D  G           PR    H
         .
         .
      0x43 C AN A           G           PR U  H
      0x44 D AN A           G           PR U  H
      0x45 E AN A           G           PR U  H
      0x46 F AN A           G           PR U  H
      0x47 G AN A           G           PR U
         .
         .
   *************************************************************/
}