D.4 The ctype.h Module
#include <ctype.h>
Defines a set of functions for classifying and transforming individual characters.
Functions
Character Classification Functions
|
int isalnum(char c); Checks whether the given character is an alphanumeric character.
|
|
int isalpha(char c); Checks whether the given character is an alphabetic letter.
|
|
int isblank(char c); Checks whether the given character is space character.
|
|
int iscntrl(char c); Checks whether the given character is a control character.
|
|
int isdigit(char c); Checks whether the given character is a digit character (0 - 9).
|
|
int isgraph(char c); Checks whether the given character is a character with graphical representation.
|
|
int islower(char c); Checks whether the given character is a lowercase character (a - z).
|
|
int isprint(char c); Checks whether the given character is a printable character.
|
|
int ispunct(char c); Checks whether the given character is a punctuation character.
|
|
int isspace(char c); Checks whether the given character is a white-space character.
|
|
int isupper(char c); Checks whether the given character is a uppercase character (A - Z).
|
|
int isxdigit(char c); Checks whether the given character is a hexadecimal character (0-9, a-f, A-F).
|
Character Conversion Functions
|
int tolower(char c); Converts and returns the given character to its lowercase equivalent.
|
|
int toupper(char c); Converts and returns the given character to its uppercase equivalent.
|
Detailed Description
int isalpha(char c);
Checks whether the given character is an alphabetic letter.
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if the character is an alphabetic letter or 0 (false) otherwise.
int isalnum(char c);
Checks whether the given character is an alphanumeric character. That is, is the character a digit or an uppercase or lowercase letter.
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is an alphanumeric character or 0 (false) otherwise.
int isblank(char c);
Checks whether the given character is space character. A space character is either a blank space or the tab (
'\t') character.- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a space character or 0 (false) otherwise.
int isspace(char c);
Checks whether the given character is a white-space character. A white-space character is any of the following:
| Value | Description | |
|---|---|---|
| ' ' | blank space | |
| '\n' | newline | |
| '\r' | carriage return | |
| '\t' | horizontal tab | |
| '\v' | vertical tab | |
| '\f' | form feed |
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a white-space character or 0 (false) otherwise.
int isdigit(char c);
Checks whether the given character is a digit character (0 - 9).
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a digit character or 0 (false) otherwise.
int isxdigit(char c);
Checks whether the given character is a hexadecimal character (0-9, a-f, A-F).
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a hexadecimal character or 0 (false) otherwise.
int islower(char c);
Checks whether the given character is a lowercase character (a - z).
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a lowercase character or 0 (false) otherwise.
int isupper(char c);
Checks whether the given character is a uppercase character (A - Z).
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a uppercase character or 0 (false) otherwise.
int ispunct(char c);
Checks whether the given character is a punctuation character. A punctuation character is considered to be any printable character which a space character or an alphanumeric character.
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a punctuation character or 0 (false) otherwise.
int iscntrl(char c);
Checks whether the given character is a control character. A control character is a character that is not printable on the display. This is the opposite of a printable character.
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a control character or 0 (false) otherwise.
int isprint(char c);
Checks whether the given character is a printable character. A printable character is a character that can be displayed on the terminal, it occupies a display position. This is the opposite of a control character.
- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a printable character or 0 (false) otherwise.
int isgraph(char c);
Checks whether the given character is a character with graphical representation. The characters with graphical representation are those characters that can be printed and have a graphical representation. This is the same as the printable characters other than a blank space
' '.- Parameters:
- c
- The character to be evaluated.
- Returns:
- A a non-zero value (true) if character is a graphical character or 0 (false) otherwise.
int tolower(char c);
Converts and returns the given character to its lowercase equivalent. If
c is an uppercase character, it is converted and returned. Otherwise, c is returned.- Parameters:
- c
- The character to be converted.
- Returns:
-
The lowercase equivalent of the given character if
cis an uppercase character, orc, otherwise.
int toupper(char c);
Converts and returns the given character to its uppercase equivalent. If
c is a lowercase character, it is converted and returned. Otherwise, c is returned.- Parameters:
- c
- The character to be converted.
- Returns:
-
The uppercase equivalent of the given character if
cis a lowercase character, orc, otherwise.