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", iswprint(wc) ? wc : ' ');
printf("%s", iswalnum(wc) ? " AN" : " ");
printf("%s", iswalpha(wc) ? " A " : " ");
printf("%s", iswcntrl(wc) ? " C " : " ");
printf("%s", iswdigit(wc) ? " D " : " ");
printf("%s", iswgraph(wc) ? " G " : " ");
printf("%s", iswlower(wc) ? " L " : " ");
printf("%s", iswpunct(wc) ? " PU" : " ");
printf("%s", iswspace(wc) ? " S " : " ");
printf("%s", iswprint(wc) ? " PR" : " ");
printf("%s", iswupper(wc) ? " U " : " ");
printf("%s", iswxdigit(wc) ? " H " : " ");
putchar('\n');
}
return 0;
/**********************************************************
The output should be similar to :
:
0x20 S PR
0x21 ! G PU PR
0x22 " G PU PR
0x23 # G PU PR
0x24 $ G PU PR
0x25 % G PU PR
0x26 & G PU PR
0x27 ' G PU PR
0x28 ( G PU PR
0x29 ) G PU PR
0x2a * G PU PR
0x2b + G PU PR
0x2c , G PU PR
0x2d - G PU PR
0x2e . G PU PR
0x2f / 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
0x36 6 AN D G PR H
0x37 7 AN D G PR H
0x38 8 AN D G PR H
0x39 9 AN D G PR H
:
************************************************************/
}