Written: August 15, 2026
Character classification is a staple lab: decide whether input is a letter, digit, or something else.
This walkthrough keeps the logic small and readable so you can type it, run it, and then change one input at a time to see what happens.
What you will build
Compare against ‘A’..’Z’, ‘a’..’z’, and ‘0’..’9′. Everything else is treated as special for this exercise.
- Read one character
- Test alphabet ranges
- Else test digit range
- Else print special
Working C example
include <stdio.h>
int main(void) {
char ch;
printf("Enter a character: ");
if (scanf(" %c", &ch) != 1) return 1;
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
printf("Alphabet\n");
} else if (ch >= '0' && ch <= '9') {
printf("Digit\n");
} else {
printf("Special character\n");
}
return 0;
}
How the logic works
Read the program top to bottom: includes and main first, then the statements that change variables, then the print that proves the result.
If your output looks wrong, print the variables before and after the critical lines. That single habit catches most beginner bugs faster than rewriting the whole file.
Leading space in scanf(” %c”) skips leftover newlines so interactive runs behave predictably.
Keep learning
If this walkthrough on C Program to Check Character Type helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.
Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.