C program for testing the character type

There are some predefined functions available in "ctype.h" library for analyzing the character input and converting them.

Analysis Functions

The character analysis functions are listed below −

FunctionChecks whether entered character is
isalphaAn alphabet (or) not
isdigitA digit (or) not
isspace QA space, a newline (or) tab
ispunct (A special symbol (or) not
islowerA lower case letter of alphabet
isupper QAn upper case letter of alphabet
isalphanumericAn alphabet/digit or not

Converting Functions

The converting functions are listed below −

tolower()Converts an upper case alphabet to lower case
toupper QConverts a lower case alphabet to upper case


Following is the C program for character analysis and conversion functions which are used to test the character type −

 Live Demo

#include <stdio.h>
#include <ctype.h>
   char character;
   printf("Press any key digit or alphabet
");    character = getchar();    if (isalpha(character) > 0)       printf("The character is a letter.");    else       if (isdigit (character) > 0)          printf("The character is a digit.");       else    printf("The character is not alphanumeric."); }


When the above program is executed, it produces the following result −

Run 1:
Press any key digit or alphabet
The character is a digit.
Run 2:
Press any key digit or alphabet
The character is a letter.
Run 3:
Press any key digit or alphabet
The character is not alphanumeric.