Skip to content

Character handling (ctype.h)

Include ctype.h for ASCII character classification and case conversion functions.

Functions

Function Summary
int isalnum(int c) Test for an ASCII alphabetic character or decimal digit.
int isalpha(int c) Test for an ASCII alphabetic character.
int iscntrl(int c) Test for an ASCII control character.
int isdigit(int c) Test for an ASCII decimal digit.
int islower(int c) Test for an ASCII lowercase letter.
int isprint(int c) Test for an ASCII printable character, including space.
int ispunct(int c) Test for an ASCII punctuation character.
int isspace(int c) Test for ASCII whitespace.
int isupper(int c) Test for an ASCII uppercase letter.
int isxdigit(int c) Test for an ASCII hexadecimal digit.
int tolower(int c) Convert an ASCII uppercase letter to lowercase, leaving other characters unchanged.
int toupper(int c) Convert an ASCII lowercase letter to uppercase, leaving other characters unchanged.

Runtime model

The character functions use ASCII classification rules. Each function takes an int; the classification functions return non-zero for a match, while toupper and tolower return the converted character or the original character when no conversion applies.

Pass either EOF or a value representable as unsigned char; this matters for portable source that might handle bytes with the high bit set.

Character classification and conversion

#include <ctype.h>

void uppercase(char *s)
{
    char *p;

    for (p = s; *p; ++p)
        *p = toupper(*p);
}