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))
ch = getchar();
if(ch == '.') break;
if(isupper(ch)) printf("%c is uppercase\n", ch);
S is uppercase