isalnum() – isxdigit() — Test Integer Value
Format
#include <ctype.h>
int isalnum(int c);
/* Test for upper- or lowercase letters, or decimal digit */
int isalpha(int c);
/* Test for alphabetic character */
int isblank(int c);
/* Test for blank or tab character */
int iscntrl(int c);
/* Test for any control character */
int isdigit(int c);
/* Test for decimal digit */
int isgraph(int c);
/* Test for printable character excluding space */
int islower(int c);
/* Test for lowercase */
int isprint(int c);
/* Test for printable character including space */
int ispunct(int c);
/* Test for any nonalphanumeric printable character */
/* excluding space */
int isspace(int c);
/* Test for whitespace character */
int isupper(int c);
/* Test for uppercase */
int isxdigit(int c);
/* Test for hexadecimal digit */
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of these functions might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
The <ctype.h> functions listed test a character with an integer value.
Return Value
These functions return a nonzero
value if the integer satisfies the test condition, or a zero value
if it does not. The integer variable c must
be representable as an unsigned char.
Note: EOF is
a valid input value.
Example
This example analyzes all characters between code 0x0 and code UPPER_LIMIT, printing A for alphabetic characters, AN for alphanumerics, B for blank or tab characters, U for uppercase, L for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for punctuation, PR for printable characters, G for graphics characters, and C for control characters. This example prints the code if printable.
The output of this example is a 256-line table showing
the characters from 0 to 255 that possess the attributes
tested.
#include <stdio.h>
#include <ctype.h>
#define UPPER_LIMIT 0xFF
int main(void)
{
int ch;
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 ", isblank(ch) ? "B" : " ");
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');
}
}