Syntax
#include <ctype.h>
/* test for: */
int isalnum(int c); /* alphanumeric character */
int isalpha(int c); /* alphabetic character */
int iscntrl(int c); /* control character */
int isdigit(int c); /* decimal digit */
int isgraph(int c); /* printable character, excluding space */
int islower(int c); /* lowercase character */
int isprint(int c); /* printable character, including space */
int ispunct(int c); /* nonalphanumeric printable character, excluding space */
int isspace(int c); /* whitespace character */
int isupper(int c); /* uppercase character */
int isxdigit(int c); /* hexadecimal digit */
Description
These functions test a given integer value c to determine if it has a certain property as defined by the LC_CTYPE category of your current locale. The value of c must be representable as an unsigned char, or EOF.
The functions test for the following:
isalnum
You can redefine any character class in the LC_CTYPE category of the current locale, with some restrictions. See the section about the LC_CTYPE class in the VisualAge C++ Programming Guide for details about these restrictions.
These functions return a nonzero value if the integer satisfies the test condition, or 0 if it does not.
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 <ctype.h>
#include <locale.h>
#define UPPER_LIMIT 0xFF
int main(void)
{
int ch;
setlocale(LC_ALL, "En_US");
for (ch = 0; ch <= UPPER_LIMIT; ++ch) {
printf("%#04x ", ch);
printf("%c", isprint(ch) ? ch : ' ');
printf("%s", isalnum(ch) ? " AN" : " ");
printf("%s", isalpha(ch) ? " A " : " ");
printf("%s", iscntrl(ch) ? " C " : " ");
printf("%s", isdigit(ch) ? " D " : " ");
printf("%s", isgraph(ch) ? " G " : " ");
printf("%s", islower(ch) ? " L " : " ");
printf("%s", ispunct(ch) ? " PU" : " ");
printf("%s", isspace(ch) ? " S " : " ");
printf("%s", isprint(ch) ? " PR" : " ");
printf("%s", isupper(ch) ? " U " : " ");
printf("%s", isxdigit(ch) ? " 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
:
****************************************************************************/
}
Related Information