Write a C program

Write a C program

Write a C program that prompts the user to enter a line of text (up to 50 characters). It should then convert the text entered to uppercase letters and then to lowercase letters, and then to Sentence case.


Your program should use a character array: text[51]. It should use the gets function to prompt the user for the line of text.

Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section).

The dialog with the user must look like:
Enter a line of text (up to 50 characters):
ThiS is A LiNe of teXt! And this is TOO.

The line of text in uppercase is:
THIS IS A LINE OF TEXT! AND THIS IS TOO.

The line of text in lowercase is:
this is a line of text! and this is too.
The line of text in sentence case is:
This is a line of text! And this is too.

 
Note: The coral text represents the "output" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the blue area above. Again, for clarity only.

Hints:

Your program requires 2 loops (either for or while). One to convert and display the string in uppercase letters, and the other to convert and display the string in lowercase letters.

Your program should use the C standard library functions toupper in one of the loops, and tolower in the other loop, to convert the string. Both of these functions are found in the header file ctype.h.

 Real BIG hint:

You can click on the Assign_4_Hint link which provides a solution to the program using array notation. You can use it as a guide, if you so choose. An arrow symbol (-) at the beginning of a particular line of code indicates which lines of code need to be modified.

 

In the sentence case make sure every first letter after a period, exclamation or question mark is uppercase.
Powered by