C - Test letter range

Description

Test letter range

Demo

#include <stdio.h>
int main(void)
{
  char letter = 0;                               // Stores an input character

  printf("Enter an upper case letter:");         // Prompt for input
  scanf(" %c", &letter);                         // Read the input character

  if((letter >= 'A') && (letter <= 'Z'))         // Verify uppercase letter
  {//from  www . ja v a 2  s  .  c o  m
    letter += 'a'-'A';                           // Convert to lowercase
    printf("You entered an uppercase %c.\n", letter);
  }
  else
    printf("You did not enter an uppercase letter.\n");
  return 0;
}

Result

The following expressing converts uppercase to lowercase:

letter += 'a'-'A';                               // Convert to lowercase