In this tutorial, you will learn about C library function islower() and isupper() which is a character handling function used to check whether the argument supplied is a lowercase and uppercase respectively or not.

C islower() and isupper()

We should include <ctype.h> header file to use islower() and isupper() function.

#include <ctype.h>

C islower( )


islower( ) function checks whether its argument is a lowercase character (a-z) or not.

Function prototype of islower()

int islower( int argument );

islower() function returns a true value if it’s argument is a lowercase letter and 0 otherwise.

C isupper( )


isupper( ) function checks whether its argument is a uppercase character (A-Z) or not.

Function prototype of isupper( )

int isupper( int argument );

isupper() returns a true value if its argument is a uppercase and 0 otherwise.

[adsense1]

C islower() and isupper(): C program to check whether a character is lowercase or uppercase.

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

int main()
{
   printf("Demonstration of islower:\n");
   printf("\n%s%s", islower('a') ? "a is a " : "a is not a ", "lowercase letter");
   printf("\n%s%s", islower('A') ? "A is a " : "A is not a ", "lowercase letter");
   printf("\n%s%s", islower('@') ? "@ is a " : "@ is not a ", "lowercase letter");
   printf("\n%s%s", islower('3') ? "3 is a " : "3 is not a ", "lowercase letter");



   printf("\n\nDemonstration of isupper:\n");
   printf("\n%s%s", isupper('a') ? "a is a " : "a is not a ", "uppercase letter");
   printf("\n%s%s", isupper('A') ? "A is a " : "A is not a ", "uppercase letter");
   printf("\n%s%s", isupper('@') ? "@ is a " : "@ is not a ", "uppercase letter");
   printf("\n%s%s", isupper('3') ? "3 is a " : "3 is not a ", "uppercase letter");
   return 0;

}

Output

Demonstration of islower:

a is a lowercase letter
A is not a lowercase letter
@ is not a lowercase letter
3 is not a lowercase letter

Demonstration of isupper:

a is not a uppercase letter
A is a uppercase letter
@ is not a uppercase letter
3 is not a uppercase letter

Explanation

In the above program, we have used conditional operator (?:) for checking whether the character is lowercase or uppercase.

printf("\n%s%s", islower('a') ? "a is a " : "a is not a ", "lowercase letter");

Here, if islower('a') codition is true "a is a" is printed else "a is not a" is printed.
Same is the case with other expressions.