C isalnum function checks its argument is either a letter of the alphabet or a digit
Syntax
C isalnum
function has the following syntax.
int isalnum(int ch);
Header
C isalnum
function is from the header file ctype.h
.
Description
C isalnum
function returns nonzero if its argument is either a letter of the
alphabet or a digit.
Example
The following code uses the C isalnum
function to check
if a character is a letter or number. The letter itself is
got from the user input. If the input is .
the program will exit.
#include <ctype.h>
#include <stdio.h>
/*from www . j a v a2 s . c o m*/
int main(void)
{
char ch;
printf(". to exit:");
for(;;) {
ch = getc(stdin);
if(ch == '.')
break;
if(isalnum(ch))
printf("%c is alphanumeric\n", ch);
}
return 0;
}
The code above generates the following result.