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 <stdio.h> #include <stdlib.h> #include <ctype.h> #include <locale.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)
{
int ch;
if (NULL == setlocale(LC_ALL, LOCNAME)) {
printf("Locale \"%s\" could not be loaded\n", LOCNAME);
exit(1);
}
for (ch = 0; ch <= UPPER_LIMIT; ++ch) {
printf("%3d ", ch);
printf("%#04x ", ch);
printf("%3s ", isalnum(ch)?"AN":" ");
printf("%2s ", isalpha(ch)?"A":" ");
printf("%2s", iscntrl(ch)?"C":" ");
printf("%2s", isdigit(ch)?"D":" ");
printf("%2s", isgraph(ch)?"G":" ");
printf("%2s", islower(ch)?"L":" ");
printf(" %c", isprint(ch)?ch:' ');
printf("%3s", ispunct(ch)?"PU":" ");
printf("%2s", isspace(ch)?"S":" ");
printf("%3s", isprint(ch)?"PR":" ");
printf("%2s", isupper(ch)?"U":" ");
printf("%2s", isxdigit(ch)?"X":" ");
putchar('\n');
}
return 0;
/***********************************************************
The output of this example is a 128-line table showing
the characters from 0 to 127 that possess the attributes
tested.
***********************************************************/
}