isalnum() to isxdigit() — Test integer value
Standards
| Standards / Extensions | C or C++ | Dependencies |
|---|---|---|
ISO C
POSIX.1 XPG4 XPG4.2 C99 Single UNIX Specification, Version 3 |
both |
Format
#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);General description
The functions that are 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.
- For C only: do not include ctype.h.
- Specify
#undef, for example,#undef islower - Surround the call statement by parentheses, for example,
(islower)('a')
- isalnum()
- Test for an upper- or lowercase letter, or a decimal digit, as
defined in the
alnumlocale source file and in thealnumclass of the LC_CTYPE category of the current locale. - isalpha()
- Test for an alphabetic
character, as defined in the
alphalocale source file and in thealphaclass of the LC_CTYPE category of the current locale. - iscntrl()
- Test for any
control character, as defined in the
cntrllocale source file and in thecntrlclass of the LC_CTYPE category of the current locale. - isdigit()
- Test for a decimal
digit, as defined in the
digitlocale source file and in thedigitclass of the LC_CTYPE category of the current locale. - isgraph()
- Test for a printable
character excluding space, as defined in the
graphlocale source file and in thegraphclass of the LC_CTYPE category of the current locale. - islower()
- Test for a lowercase
character, as defined in the
lowerlocale source file and in thelowerclass of the LC_CTYPE category of the current locale. - isprint()
- Test
for a printable character including space, as defined in the
printlocale source file and in theprintclass of the LC_CTYPE category of the current locale. - ispunct()
- Test for any
nonalphanumeric printable character, excluding space, as defined in
the
punctlocale source file and in thepunctclass of the LC_CTYPE category of the current locale. - isspace()
- Test for a white
space character, as defined in the
spacelocale source file and in thespaceclass of the LC_CTYPE category of the current locale. - isupper()
- Test for an uppercase
character, as defined in the
upperlocale source file and in theupperclass of the LC_CTYPE category of the current locale. - isxdigit()
- Test for a hexadecimal
digit, as defined in the
xdigitlocale source file and in thexdigitclass of the LC_CTYPE category of the current locale.
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.
Returned value
If the integer satisfies the test condition, these functions return nonzero.
If the integer does not satisfy the test condition, these functions return 0.
Example
/* 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');
}
}