C program for testing the character type

CServer Side ProgrammingProgramming

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\n");
   character = getchar();
   if (isalpha(character) > 0)
      printf("The character is a letter.");
      if (isdigit (character) > 0)
         printf("The character is a digit.");
   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.
Published on 26-Mar-2021 12:02:15