C - Use function to check uppercase and lowercase letter


ctype.h standard header file has functions isalpha(), isupper(), and islower() that test the character you pass as the argument.

They return true if the argument is alphabetic, uppercase, or lowercase, respectively.

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


#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  .  c  om
        printf("You did not enter an uppercase letter.\n");
      return 0;