by Dinesh Thakur Category: C Programming (Pratical)

A character is an uppercase letter if its value in the range 'A' to ' Z ' (both inclusive). The program segment given below tests whether a given character is an uppercase letter or not.

if (ch>= 'A' && ch<= 'Z')

printf("%c is uppercase letter\n", ch);

else printf("%c is not uppercase letter\n", ch);

This example uses an if-else statement to determine whether the character in variable ch is an ·uppercase letter or not. Note that if the condition in the if statement evaluates as false, we cannot assume the character to be a lowercase letter as it may be any other character such as a digit, punctuation symbol, space, etc.

We can rewrite the condition in the above if statement using the values of character constants 'A' and 'z' as (ch>= 65 && ch<= 90). However, this should be avoided for the reasons mentioned above. Also, recall that we can use the isupper library function to perform the test for uppercase characters and rewrite the if statement as if (isupper(ch))

void main()
char ch;
ch = getchar();
if(ch == '.') break;
if(isupper(ch)) printf("%c is uppercase\n", ch);
S is uppercase

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.