Use toupper() and the tolower() functions to convert a character to uppercase and lowercase, respectively. - C Data Type

C examples for Data Type:char

Description

Use toupper() and the tolower() functions to convert a character to uppercase and lowercase, respectively.

Demo Code

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

int main(void)
{
    char letter = 0;                          // Stores a character
    printf("Enter an uppercase letter:");     // Prompt for input
    scanf("%c", &letter);                     // Read a character

    if(isalpha(letter) && isupper(letter))
       printf("You entered an uppercase %c.\n", tolower(letter));
    else/*from w w w.  j a v a 2s .  co  m*/
       printf("You did not enter an uppercase letter.\n");
       
    return 0;
}

Result


Related Tutorials