isalnum() function in C Language


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
");    else    printf("The character is not alphanumeric
");    if(isalnum(val2))    printf("The character is alphanumeric
");    else    printf("The character is not alphanumeric");    if(isalnum(val3))    printf("The character is alphanumeric
");    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
"); else printf("The character is not alphanumeric
");

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements