check character is uppercase or lowercase in C language

program-to-check-character-is-uppercase-or-lowercase-in-c

Check Character is Uppercase or Lowercase Program Description:

Write a C Program to check character is uppercase or lowercase using the if else statement.

The program should accept a character from the user and display whether the character is Lower case or Uppercase character.

Excepted Input and Output:

Example 1: Input:

Enter a character : m

Output:

m is Lower Case Character

Example 2: Input:

Enter a character : V

Output:

V is Upper case character

Example 3: Input:

Enter a character : 8

Output:

Invalid Input, Please enter valid Alphabet

Pre-Requisites:

It is recommended to know the understanding of if else statement and goto statements

please look at the following articles for more details

Program Explanation:

We can use two different methods to check the case of the alphabet

  • Using Predefined functions like islower() and isupper()
  • Using Manual ASCII Checks

Method 1: Check character is uppercase or lowercase using the predefined functions:

  • We can use predefined functions like islower() and isupper() from the ctype.h header file.
  • We use the if else statement with the islower() and isupper() functions.
  • The islower(ch) function will check the character ch and returns true if the ch is Lower Case Character
  • The isupper(ch) function will check the character ch and returns true if the ch is Upper Case Character
  • If the above two conditions are False, Then the given character ch is not a valid Alphabet. So we display the error. And takes the controls back to the start of the program using the goto statement.

Check character is uppercase or lowercase in C Language:

Program Output:

Method 2: Check whether the character is uppercase or lowercase Using Manual ASCII Checks

In this method, We manually compare the ASCII value of the given character ch manually with the lower case characters and upper case characters ASCII Values.

If the character ch appears between the lowercase characters a and z, Then ch is Lower Case character. We can use the following logic to check it – (ch >= ‘a’ && ch <= ‘z’)

Similarly, We can check for upper case letters as well, If the ch ASCII value is in between the A and Z ASCII values. We are using the following logic to check the upper case character. (ch >= ‘A’ && ch <= ‘Z’)

Program Output:

Related Articles:

C Tutorials Index:

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

1 Response

  1. […] C Program to check character is Uppercase or Lowercase […]

Leave a Reply