isupper() Function Example in C Programming

In this source code example, we will see how to use the isupper() function in C programming with an example.

isupper() Function Overview

The isupper() function is found in the <ctype.h> library in C. This function checks whether the provided character is an uppercase alphabetic character (A-Z). 

Key Points: 

- You need to include the <ctype.h> header to utilize the function. 

- The function accepts an int, which represents the ASCII value of the character. 

- It returns a non-zero value (true) if the character is an uppercase alphabetic letter and zero (false) otherwise.

Source Code Example

#include <stdio.h> #include <ctype.h> // Required for isupper() int main() { char ch; printf("Enter a character: "); scanf("%c", &ch); if (isupper(ch)) { printf("The character you entered is an uppercase letter.\n"); } else { printf("The character you entered is not an uppercase letter.\n"); } return 0; } 

Output

Enter a character: A The character you entered is an uppercase letter. Or Enter a character: a The character you entered is not an uppercase letter. 

Explanation

1. The required header files are initially included: stdio.h for standard I/O functions and ctype.h for the isupper() function.

2. The main() function starts by declaring a character variable ch.

3. A prompt asks the user to input a character, which is then stored in the ch variable.

4. The isupper() function checks if the character is an uppercase alphabetic letter.

5. A message is displayed indicating whether the character is uppercase or not.


Comments