C programming ctype.h function - int toupper(int c)

www.‮‬theitroad.com

The int toupper(int c) function in the ctype.h library of C programming is used to convert a given lowercase letter to its corresponding uppercase letter.

The toupper() function takes a single integer argument c, which is the character to be converted to uppercase. The function returns an integer value, which is the uppercase version of the input character c if it is a lowercase letter, and the same character c otherwise.

Here's an example of how to use the toupper() function in C:

#include <stdio.h>
#include <ctype.h>

int main() {
    char c = 'd';
    char uc = toupper(c);
    printf("The uppercase version of %c is %c\n", c, uc);
    return 0;
}

In this example, the toupper() function is used to convert the lowercase letter 'd' to its corresponding uppercase letter. The function returns the character 'D', which is then assigned to the variable uc. The output of the program will be: 'The uppercase version of d is D'.

If the input character had already been an uppercase letter such as 'F', the toupper() function would return the same character 'F', and the output would be: 'The uppercase version of F is F'.