CIS 71 (section 1): Homework 5

Handed out: 2/18/97
Due: by 2:30pm on 2/25/97
Email program to btrianta@thunder.temple.edu

Write a program that in a loop prompts the user to enter a text line and then prints out the line replacing capital letters by lowercase letters and streaks of two or more spaces by single spaces.
The loop is terminated when the user just types a carriage return.

Here is an example of the interactions in a possible run:

Enter line [CR to exit] : Roses   are   VERY red
roses are very red
Enter line [CR to exit] :    VioLETS ARE    Blue 
 violets are blue
Enter line [CR to exit] :

Your main program should use a function written by you:

char makelower(char c);
given a character c, returns it as is if it is not an uppercase letter, otherwise it returns the corresponding lowercase letter.

As a comment at the beginning of your program you should do a case analysis for this problem: problem statement, analysis, design, and testing.

Hints

  1. It is easy to check if a character c is an upper case letter: It is an uppercase letter if it is no less than 'A' and no greater than 'Z'
  2. If c is an uppercase letter then the corresponding lowercase letter is ('a'-'A'+c). You can check on this formula by printing out the numeric codes of the printable characters [see example program to do that].