Tests for membership in subsets of the character set.
#include <ctype.h> int isalnum(int c); int isalpha(int c); int isblank(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);
c
A character value to test.
These functions test ASCII characters ( 0x00 to 0x7F) and the EOF value. The results of these functions are not defined for character values in the range 0x80 to 0xFF.
The c argument is of type int so that the EOF value, which is outside the range of the char type, may also be tested.
| Function | returns true if c is one of these values. |
|---|---|
| isalnum(c) | Alphanumeric characters. For the "C"locale, "a" to "z" , "A" to "Z" , or "0" to "9". |
| isalpha(c) | Alphabetic characters. For the "C"locale, "a" to "z" or "A" to "Z". |
| isblank(c) | Word-separating whitespace. For the "C"locale, the space and tab characters. |
| iscntrl(c) | Non-printing control characters. The delete character (0x7F) or an ordinary control character from 0x00 to 0x1F. |
| isdigit(c) | Numeric characters. |
| isgraph(c) | Non-space printing character. |
| islower(c) | A lowercase alphabetic character, from"a" to "z". |
| isprint(c) | A printable character, including the space character. The compliment of the subset that iscntrl()tests for. |
| ispunct(c) | A punctuation character. A punctuation character is not in the subsets for which isalnum(), isblank(), or iscntrl() return true. |
| isspace(c) | A whitespace character. A space, tab, return, new line, vertical tab, or form feed. |
| isupper(c) | An uppercase alphabetic character, from "A" to "Z". |
| isxdigit(c) | A hexadecimal character. From "0" to "9" , "a" to "f" , or "A" to "F" . |
#include <stdio.h> #include <ctype.h> int main(void) { char *test = "Fb6# 9,"; isalnum(test[0]) ? printf("%c is alphanumerical\n", test[0]) : printf("%c is not alphanumerical\n", test[0]); isalpha(test[0]) ? printf("%c is alphabetical\n", test[0]) : printf("%c is not alphabetical\n", test[0]); isblank(test[4]) ? printf("%c is a blank space\n", test[4]) : printf("%c is not a blank space\n", test[4]); iscntrl(test[0]) ? printf("%c is a control character\n", test[0]) : printf("%c is not a control character\n", test[0]); isdigit(test[2]) ? printf("%c is a digit\n", test[2]) : printf("%c is not a digit\n", test[2]) ; isgraph(test[0]) ? printf("%c is graphical \n", test[0]) : printf("%c is not graphical\n", test[0]); islower(test[1]) ? printf("%c is lowercase \n", test[1]) : printf("%c is not lowercase\n", test[1]); isprint(test[3]) ? printf("%c is printable\n", test[3]) : printf("%c is not printable\n", test[3]); ispunct(test[6]) ? printf("%c is a punctuation mark\n", test[6]) : printf("%c is not punctuation mark\n", test[6]); isspace(test[4]) ? printf("%c is a space\n", test[4]) : printf("%c is not a space\n", test[4]); isupper(test[0]) ? printf("%c is uppercase \n", test[1]) : printf("%c is not uppercase\n", test[1]); isxdigit(test[5]) ? printf("%c is a hexadecimal digit\n", test[5]) : printf("%c is not a hexadecimal digit\n", test[5]); return 0; } Output: F is alphanumerical F is alphabetical is a blank sapce F is not a control character 6 is a digit F is graphical b is lower case # is printable , is a punctuation mark is a space F is uppercase 9 is a hexadecimal digit