C Program to Check Character is Alphabet Digit or Special Character

How to write a C Program to Check Character is Alphabet Digit or Special Character with an example. For this, we are going to use the Built-in function isalpha, isdigit, and ASCII Codes.

C Program to Check Character is Alphabet Digit or Special Character Example 1

This C program allows the user to enter one character. And then, it will check whether the character is Alphabet, digit, or Special Characters.

In this example, we are going to use C Programming built-in functions isalpha and isdigit to find whether the character is Alphabet or Digit

/* C Program to check Character is Alphabet Digit or Special Character */
 
#include <stdio.h>
#include<ctype.h>
 
int main()
{
	char ch;
  	
	printf(" Please Enter any character :  ");
  	scanf("%c", &ch);
  
  	if (isalpha(ch))
  	{
  		printf("\n %c is an Alphabet", ch);  	
  	} 
  	else if (isdigit(ch))
  	{
  		printf("\n %c is a Digit", ch);  	
  	}
  	else
    	printf("\n %c is a Special Character", ch);
  
  	return 0;
}

C Alphabet, Digit, or Special Character output

 Please Enter any character :  K

 K is an Alphabet

Let us check whether 9 is an Alphabet or Digit or Special Character

 Please Enter any character :  9

 9 is a Digit

Let us check Special Character

 Please Enter any character :  @

 @ is a Special Character

Program to Check Character is Alphabet Digit or Special Character Example 2

In this program, to check Alphabet, digit or special character, we are using the alphabets and digits directly inside the Else If Statement.

/* C Program to check Character is Alphabet Digit or Special Character */
 
#include <stdio.h>
 
int main()
{
  	char ch;
  	
  	printf(" Please Enter any character :  ");
  	scanf("%c", &ch);
  
  	if( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') )
  	{
  		printf("\n %c is an Alphabet", ch);  	
 	}
  	else if (ch >= '0' && ch <= '9')
  	{
  		printf("\n %c is a Digit", ch);  	
  	}    
  	else
    	printf("\n %c is a Special Character", ch);
  
  	return 0;
}
 Please Enter any character :  4

 4 is a Digit

Program to Check Character is Alphabet Digit or Special Character Example 3

In this program, we are using the ASCII Table values to check whether the input character is Alphabet or Digit or special character.

/* C Program to check Character is Alphabet Digit or Special Character */
 
#include <stdio.h>
 
int main()
{
  	char ch;
  	
  	printf(" Please Enter any character :  ");
  	scanf("%c", &ch);
  
 	if (ch >= 48 && ch <= 57)
  	{
  		printf("\n %c is a Digit", ch);  	
  	}
  	else if ( (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) )
  	{
  		printf("\n %c is an Alphabet", ch);  	
  	}    
  	else
    	printf("\n %c is a Special Character", ch);
  
  	return 0;
}
C Program to check Character is Alphabet Digit or Special Character 5

Let us check whether 3 is a Digit or not

 Please Enter any character :  3

 3 is a Digit

Let us check whether $ is a special character or not

 Please Enter any character :  $

 $ is a Special Character