4.3 Character Sets and ASCII
C's char stores one character and can also be viewed as a small integer. ASCII maps common English letters, digits, and symbols to integer codes.
c
char c = 'A';
printf("%c %d\n", c, c);This prints the character and its code. The table below lists all 128 ASCII codes. Click any cell to see its decimal value, hex value, character, and category.
Loading interactive lab...
You can classify characters by comparing ranges:
c
if (c >= 'A' && c <= 'Z') {
printf("uppercase\n");
}Or use helpers from <ctype.h>:
c
#include <ctype.h>
if (isdigit(c)) {
printf("digit\n");
}The core idea is to treat a group of characters as a range or category, then test whether a character belongs to it.
Loading concept check...
Loading practice...