C Program to Check Character Type (Capital, Small, Digit, or Special Character)

When handling character input in C, one of the most useful tasks is checking what type of character was entered. This article explains how to write a C program character type checker that detects whether the input is a capital letter, small letter, digit, or special character.


Why Use a C Program Character Type Checker?

Character classification is essential when building programs that involve user input validation or text processing. By using ASCII ranges and simple conditions, a C program character type checker helps maintain clean input and prevent errors.


ASCII Ranges to Classify Characters

C language relies on ASCII values to represent characters. Here’s a quick table of ranges:

Character TypeASCII Range
Capital Letters65–90
Small Letters97–122
Digits48–57

Characters outside these ranges are classified as special characters. For a full list, visit the ASCII Table.


C Program to Identify Character Type

#include <stdio.h>

int main() {
char ch;

// Input character from user
printf("Enter any character: ");
scanf("%c", &ch);

// Check and classify
if (ch >= 'A' && ch <= 'Z') {
printf("It is a Capital Letter.\n");
}
else if (ch >= 'a' && ch <= 'z') {
printf("It is a Small Letter.\n");
}
else if (ch >= '0' && ch <= '9') {
printf("It is a Digit.\n");
}
else {
printf("It is a Special Character.\n");
}

return 0;
}

Explanation of the Code

This simple program takes a character as input and checks its ASCII value using conditional statements. If the character falls between:

  • A-Z → Capital letter
  • a-z → Small letter
  • 0-9 → Digit
  • Else → Special character

Each condition is straightforward and avoids the need for additional libraries.


Example Output

Enter any character: 9
It is a Digit.

Enter any character: B
It is a Capital Letter.

Enter any character: @
It is a Special Character.

Conclusion

Using ASCII values and condition checks, this C program character type logic helps programmers accurately classify user input. It’s a great way to practice conditional logic and input handling in C.


Getting Started with C Language for Beginners

Previous Article

Prom Makeup Inspo: Classy, Sultry, and Glam Looks for Your Big Night

Next Article

How to Create a C Program to Display Grades Based on Marks (If-Else Ladder)

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨