What is isupper() in C?

isupper() is a C library function that checks whether or not the character passed as a parameter is an uppercase letter.

Library

#include<ctype.h>

Syntax

Below is the declaration of isupper(),

int isupper(int ch);

where ch is the character to be checked. The return type of the function is int.

If the letter passed to the function is an uppercase letter, the function returns a non-zero value. Otherwise, the function returns zero.

Alternative approach

An alternative approach (without using isupper()) to check whether or not a character is an uppercase letter is to check if the character lies between 6565 and 9090 (inclusive).

If the character lies between 6565 and 9090 (inclusive), it is an uppercase letter. Otherwise, it is not.

%0 node_1622696419286 A node_1622696401612 65 node_1622696388503 B node_1622696445193 66 node_1622696449773 C node_1622696005811 67 node_1622695973457 D node_1 68 node_2 E node_3 69 node_1622695957903 F node_1622695943688 70
%0 node_1622697609476 G node_1622696419286 71 node_1622696401612 H node_1622696445193 72 node_1622696449773 I node_1622696005811 73 node_1622695973457 J node_1 74 node_2 K node_3 75 node_1622695957903 L node_1622695943688 76
%0 node_1622696419286 M node_1622696401612 77 node_1622696388503 N node_1622696445193 78 node_1622696449773 O node_1622696005811 79 node_1622695973457 P node_1 80 node_2 Q node_3 81 node_1622695957903 R node_1622695943688 82
%0 node_1622696419286 S node_1622696401612 83 node_1622696388503 T node_1622696445193 84 node_1622696449773 U node_1622696005811 85 node_1622695973457 V node_1 86 node_2 W node_3 87 node_1622695957903 X node_1622695943688 88
%0 node_1622696449773 Y node_1622696005811 89 node_1622695973457 Z node_1 90
ASCII values of uppercase letters

Code

1. With isupper()

#include<stdio.h>
#include<ctype.h>
int main() {
char str[] = {'a', '!', '2', 'M'};
int i = 0;
while (i < 4) {
int returnValue = isupper(str[i]);
if (returnValue > 0)
printf("%c is an uppercase letter.\n", str[i]);
else
printf("%c is not an uppercase letter.\n", str[i]);
++i;
}
return 0;
}

2. Without isupper()

#include<stdio.h>
#include<ctype.h>
int main() {
char str[] = {'a', '!', '2', 'M'};
int i = 0;
while (i < 4) {
if (str[i] >= 65 && str[i] <= 90)
printf("%c is an uppercase letter.\n", str[i]);
else
printf("%c is not an uppercase letter.\n", str[i]);
++i;
}
return 0;
}

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved