C programming - standard library ctype.h

www.ig‮ditfi‬ea.com

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:

  1. isalpha(int c): This function checks if the given character is an alphabetic character (a to z or A to Z).

  2. isdigit(int c): This function checks if the given character is a digit (0 to 9).

  3. isalnum(int c): This function checks if the given character is an alphanumeric character (a to z, A to Z, or 0 to 9).

  4. 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).

  5. islower(int c): This function checks if the given character is a lowercase letter (a to z).

  6. isupper(int c): This function checks if the given character is an uppercase letter (A to Z).

  7. tolower(int c): This function converts the given uppercase letter to lowercase.

  8. 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.