The ctype Library
isdigit, isalpha, toupper.
What Is ctype.h
The <ctype.h> header provides functions to classify and convert characters.
It saves you from memorizing ASCII ranges and writing manual comparisons.
#include <stdio.h>
#include <ctype.h>
int main(void) {
printf("Is 'A' alpha? %d\n", isalpha('A'));
return 0;
}isdigit
isdigit(c) returns a nonzero value if c is a digit character '0'-'9', and 0 otherwise.
#include <stdio.h>
#include <ctype.h>
int main(void) {
printf("isdigit('7') = %d\n", isdigit('7'));
printf("isdigit('x') = %d\n", isdigit('x'));
return 0;
}All lessons in this course
- Characters as Integers
- The ctype Library
- Reading Characters
- Building Char Utilities