isalnum in C Programming

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

C isalnum Syntax

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 C 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.

#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

Analysis

In this isalnum in the c program, we first declared a character variable called ch. The following C Programming statement will ask the user to enter any character. And then we use the scanf to assign the user entered a character to the 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 the 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 the below statements.

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

The above C isalnum code perfectly checks 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

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.