isalnum() function in C Language

CProgrammingServer Side Programming

The function isalnum() is used to check that the character is alphanumeric or not. It returns non-zero value, if the character is alphanumeric means letter or number otherwise, returns zero. It is declared in “ctype.h” header file.

Here is the syntax of isalnum() in C language,

int isalnum(int character);

Here,

character − The character which is to be checked.

Here is an example of isalnum() in C language,

Example

 Live Demo

#include<stdio.h>
#include<ctype.h>
int main() {
   char val1 = 's';
   char val2 = '8';
   char val3 = '$';
   if(isalnum(val1))
   printf("The character is alphanumeric\n");
   else
   printf("The character is not alphanumeric\n");
   if(isalnum(val2))
   printf("The character is alphanumeric\n");
   else
   printf("The character is not alphanumeric");
   if(isalnum(val3))
   printf("The character is alphanumeric\n");
   else
   printf("The character is not alphanumeric");
   return 0;
}

Output

The character is alphanumeric
The character is alphanumeric
The character is not alphanumeric

In the above program, three variables of char type are declared and initialized with the values. These variables are checked that these values are alphanumeric or not by using isalnum() function.

if(isalnum(val1))
printf("The character is alphanumeric\n");
else
printf("The character is not alphanumeric\n");
raja
Published on 05-Nov-2018 11:02:37
Advertisements