C programming - standard library ctype.h
The "ctype.h" header file in C programming provides a set of functions to classify and manipulate characters. These functions operate on individual characters of the ASCII character set or any other character set supported by the implementation.
Here are some of the commonly used functions in the "ctype.h" header file:
isalpha(int c): This function checks if the given character is an alphabetic character (a to z or A to Z).
isdigit(int c): This function checks if the given character is a digit (0 to 9).
isalnum(int c): This function checks if the given character is an alphanumeric character (a to z, A to Z, or 0 to 9).
isspace(int c): This function checks if the given character is a white-space character (space, tab, newline, carriage return, form feed, or vertical tab).
islower(int c): This function checks if the given character is a lowercase letter (a to z).
isupper(int c): This function checks if the given character is an uppercase letter (A to Z).
tolower(int c): This function converts the given uppercase letter to lowercase.
toupper(int c): This function converts the given lowercase letter to uppercase.
Here is an example of using the "ctype.h" header file functions in a C program:
#include <stdio.h> #include <ctype.h> int main() { char c = 'A'; // Check if the character is an uppercase letter if (isupper(c)) { printf("%c is an uppercase letter.\n", c); // Convert the uppercase letter to lowercase c = tolower(c); printf("Converted to lowercase: %c\n", c); } return 0; }
In this example, the "isupper" function is used to check if the character 'A' is an uppercase letter. If it is true, the "tolower" function is used to convert the uppercase letter to lowercase, and the result is printed to the console.