Puzzle S3

Convert to lower case

[E-4]Write a function that converts an upper case character to a lower case character and leaves all other characters unchanged. The character to be converted is passed (by value) as an int. The return value of the function is the converted character. Here is a testing program:

/* Puzzle S03 --  to lower case */

#include <stdio.h>
#include <stdlib.h>

int isUppercase( int ch )
{
}

int toLowerCase( int ch )
{
}

int main()
{
  char trials[] = {'a', 'B', 'C', '+', 'z', 0x33, 0x0C, 0x0D };
  int j, ch;
  
  for ( j=0; j<sizeof(trials); j++ )
  {
    ch = (unsigned int)trials[j] ; /* char in low order byte */
    printf("%c ", ch );
    printf("to lower case: %c\n", (char)toLowerCase(ch) );
 }
   
 return 0;
}

Note: this function is similar to the function toLower() described in <ctype.h>.



Previous Page        Answer         Next Page         Home