Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <ctype.h>
int isalnum(int c);
int isalpha(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
The functions listed above, which are all declared in ctype.h, test a given integer value. The valid integer values for c are those representable as an unsigned char or EOF.
By default, the functions are defined as macros when ctype.h is included. For better performance, the macro forms are recommended over the functional forms.
The space, uppercase, and lowercase characters can be redefined by their respective class of the LC_CTYPE in the current locale. The LC_CTYPE category is discussed in the “Internationalization: Locales and Character Sets” in z/OS XL C/C++ Programming Guide.
If the integer satisfies the test condition, these functions return nonzero.
If the integer does not satisfy the test condition, these functions return 0.
⁄* CELEBI02
This example analyzes all characters between code 0x0 and
code UPPER_LIMIT.
The output of this example is a 256-line table showing the
characters from 0 to 255, and a notification of whether they
have 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(" %c", isprint(ch) ? ch : ' ');
printf("%3s ", isalnum(ch) ? "Alphanumeric" : " ");
printf("%2s ", isalpha(ch) ? "Alphabetic" : " ");
printf("%2s", iscntrl(ch) ? "Control" : " ");
printf("%2s", isdigit(ch) ? "Digit" : " ");
printf("%2s", isgraph(ch) ? "Graphic" : " ");
printf("%2s ", islower(ch) ? "Lower" : " ");
printf("%3s", ispunct(ch) ? "Punctuation" : " ");
printf("%2s", isspace(ch) ? "Space" : " ");
printf("%3s", isprint(ch) ? "Printable" : " ");
printf("%2s ", isupper(ch) ? "Upper" : " ");
printf("%2s ", isxdigit(ch) ? "Hex" : " ");
putchar('\n');
}
}