test a character to see if it's alphanumeric
#include <ctype.h> int isalnum( int c );
The isalnum() function tests if the argument c is an alphanumeric character ('a' to 'z', 'A' to 'Z', or '0' to '9'). An alphanumeric character is any character for which isalpha() or isdigit() is true.
A nonzero value if the character is alphabetic (A-Z or a-z) or a digit (0-9), otherwise, zero.
The result is only valid for char arguments and EOF. The result is undefined for other types of arguments. |
#include <stdio.h> #include <ctype.h> void main() { if( isalnum( getchar() ) ) { printf( "is alpha-numeric\n" ); } }
ANSI
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
isalpha(), iscntrl(), isdigit(), isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(), isxdigit()