isalnum in C Programming

The C isalnum function is one of the Standard Library Functions available in C language, which is useful to check the given character is either an alphabet or a numeric value. The syntax of the isalnum in C Programming language is

The below c isalnum function will accept the single character as the parameter, and check whether the given character is either a number or an alphabet.

isalnum(char)

isalnum in C Programming Example

The isalnum method (alphanumeric) used to find the given character is either an alphabet or numeric. This C program allows the user to enter any character. Next, it checks whether the character is between A to Z, or a to z, or a numeric value using the isalnum function.

//Example for isalnum in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    printf("Please Enter Either an Alphabet, or a Number: \n");
    scanf("%c", &ch);

    if(isalnum(ch))
    {
      printf("\n You have entered an Alphanumeric Character");         
    }
    else
    {
      printf("\n %c is not an Alphanumeric Character", ch);
      printf("\n I request you to enter Valid Number, or an Alphabet");	
    }
}
isalnum in C Programming 1

Let me enter the Uppercase letter

Please Enter Either an Alphabet, or a Number: 
K

 You have entered an Alphanumeric Character

Let me enter the Numeric value

Please Enter Either an Alphabet, or a Number: 
9

 You have entered an Alphanumeric Character

In this isalnum in the c program, first, we declared a character variable called ch. The following C Programming statement will ask the user to enter any character. And then we are using the scanf to assign the user entered a character to ch variable

printf("Please Enter Either an Alphabet, or a Number: \n");
scanf("%c", &ch);

In this next line, we added the If Statement to check whether the character is between ‘A’ to ‘Z’, or ‘a’ to ‘z’, or a number using isalnum function. If the condition is True, the following statement will print

printf("\n You have entered an Alphanumeric Character");

If the above condition is FALSE, then the given character is not an Alphabet, or a number. So, this C program will print below statements

printf("\n %c is not an Alphanumeric Character", ch);
printf("\n I request you to enter Valid Number, or an Alphabet");

Above c isalnum code perfectly checking whether the given character is either an alphabet or a number. But what if, we enter the symbols

Please Enter Either an Alphabet, or a Number: 
*

 * is not an Alphanumeric Character
 I request you to enter Valid Number, or an Alphabet

Let me try with the space character

Please Enter Either an Alphabet, or a Number: 
 

   is not an Alphanumeric Character
 I request you to enter Valid Number, or an Alphabet