ctype Functions
isalpha, isdigit, isspace, toupper and tolower test and convert characters.
Example
#include <stdio.h>
#include <ctype.h>
int main(void) {
const char *s = "Hi 42!";
int l = 0, d = 0;
for (int i = 0; s[i]; i++) { if (isalpha(s[i])) l++; if (isdigit(s[i])) d++; }
printf("%d %d %c\n", l, d, toupper('x'));
return 0;
}Result
2 2 X
Exercise
Test a digit.
(c)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.