ctype.h in Language
The <ctype.h>
header file defines a set of prototypes for character handling functions.
Character Testing Functions
These functions are used to determine whether a character belongs to a specific type:
isalnum()
: Checks if the character is alphanumeric.isalpha()
: Checks if the character is a letter.isdigit()
: Checks if the character is a digit.isxdigit()
: Checks if the character is a hexadecimal digit.islower()
: Checks if the character is a lowercase letter.isupper()
: Checks if the character is an uppercase letter.isblank()
: Checks if the character is a standard whitespace character (including space, horizontal tab, or newline).isspace()
: Checks if the character is any whitespace character (such as space, newline, form feed, carriage return, vertical tab, or horizontal tab).iscntrl()
: Checks if the character is a control character (e.g., Ctrl + B).isprint()
: Checks if the character is a printable character.isgraph()
: Checks if the character is any printable character except space.ispunct()
: Checks if the character is a punctuation character (any printable character except space, letter, or digit).
These functions take an int
parameter (not a char
) because they also accept EOF as a valid argument.
If the character belongs to the specified type, the function returns a non-zero integer (typically 1, indicating true); otherwise, it returns 0 (indicating false).
Here’s an example: the user inputs a character, and the program checks if it is an English letter.
1 |
|
Character Mapping Functions
These functions return a corresponding form of a character, primarily consisting of two functions:
tolower()
: If the argument is an uppercase character, it returns the lowercase equivalent; otherwise, it returns the original character.toupper()
: If the argument is a lowercase character, it returns the uppercase equivalent; otherwise, it returns the original character.
1 | // Convert character to uppercase |
Note that these functions do not modify the original character.
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.