[E-1]
Write a function that determines if a character
is one of the upper case characters 'A' through 'Z'. If so, return 1, otherwise
return zero. Here is a prototype for the function:
int isUppercase( int ch );
The argument for the function is of type int
.
The eight bits of the character itself will be in the low order byte
of the argument.
Here is a skeleton of a testing program Finish it by completing the function. With a programming environment (such as Bloodshed Dev-C++) use copy-and-paste to copy this code into the editor window and then save it to a source file.
/* Puzzle S01 -- detect upper case characters */ #include <stdio.h> #include <stdlib.h> int isUppercase( int ch ) { . . . . } int main() { int trials[] = {'a', 'B', 'Z', ' ', '+', 'z', 'Z', 0x33 }; int j, ch; for ( j=0; j<sizeof(trials)/sizeof(int); j++ ) { ch = trials[j]; if ( isUppercase( ch ) ) printf("%c is upper case\n", ch); else printf("%c is NOT upper case\n", ch); } return 0; }
Note: this function is similar to the function isupper()
described in <ctype.h>
. In professional-level code,
use the standard function rather than your own.