A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
isalpha returns nonzero if the character is a letter: uppercase or lowercase. In the default C locale, that means A-Z and a-z. In other locales, it may include accented characters. It returns zero for digits, punctuation, whitespace, and control characters. The argument must be cast to unsigned char to avoid undefined behavior on negative values. This is the same rule as every ctype function, and I will stop repeating it after this lesson, but I will keep showing the cast in every code example.
#include <stdio.h>#include <ctype.h>int main(void) {const char *input = "Hello, World! 42";for (const char *p = input; *p; p++) {unsigned char c = (unsigned char)*p;printf("'%c' -> isalpha: %d\n", isprint(c) ? c : '?', isalpha(c));}return 0;}
Letters return nonzero. Everything else returns zero. The comma, spaces, exclamation mark, and digits all fail the test. This is equivalent to isupper(c) || islower(c), but isalpha is a single call and locale-aware. Use it for identifier validation, word boundary detection, and input filtering.
isalpha is one building block in the ctype classification set. Combined with isdigit, isspace, and ispunct, you can categorize any character in a single pass. Next: isdigit, for testing numeric characters.
Finish the lesson once you have worked through the material. This awards ★ 10 XP.