Introduction
In this guide, you will learn how to write a C program character type checker that determines whether an entered character is a capital letter, small letter, digit, or a special character. This topic is frequently covered in GTU practical exams and helps build a strong foundation in C programming.
Understanding how to classify characters using ASCII values and conditional statements is essential for any beginner. This blog post is aimed at GTU students preparing for practicals and viva.
Understanding ASCII in C
Each character is stored using an ASCII value in C:
- Capital letters: A to Z → ASCII 65–90
- Small letters: a to z → ASCII 97–122
- Digits: 0 to 9 → ASCII 48–57
- Other symbols are considered special characters
With these ranges, we can easily identify the character type.
C Program to Check Character Type
#include <stdio.h> int main() { char ch; printf("Enter any character: "); scanf("%c", &ch); if (ch >= 'A' && ch <= 'Z') { printf("The character is a CAPITAL LETTER.\n"); } else if (ch >= 'a' && ch <= 'z') { printf("The character is a SMALL LETTER.\n"); } else if (ch >= '0' && ch <= '9') { printf("The character is a DIGIT.\n"); } else { printf("The character is a SPECIAL CHARACTER.\n"); } return 0; }
Sample Output
Enter any character: M The character is a CAPITAL LETTER. Enter any character: 4 The character is a DIGIT. Enter any character: * The character is a SPECIAL CHARACTER.
Why This C Program Character Type Logic Works
The program uses conditional checks based on character ranges from the ASCII table. This method is simple, fast, and used frequently in programming assessments.
GTU Viva Questions Based on This Program
- What is the ASCII value of ‘A’?
- How do you differentiate between alphabets and digits?
- Can this logic be used with getchar() instead of scanf()?
Conclusion
This C program character type example demonstrates a simple yet effective way to classify any user input. It is a common GTU practical program and builds your understanding of C conditionals and ASCII usage.
This explanation and code meet academic requirements and prepare you for C programming interviews and university exams.