Develop a functional c program that implements a design and


Strings

Learning Objectives and Outcomes

Develop a functional C program that implements a design and create a C program that declares and uses strings.

Required Setup and Tools

Standard computer lab with Pelles C and Microsoft Visio installed

Recommended Procedures

Task: Create a program to read and reverse a word.

Create a new project named "ReverseWord" and a new source file named "reverse.c". Create a main() function with the usual header and other supporting code. Add a declaration of a string variable named "word" that can hold at least 29 characters (plus the terminator). Add code to print a prompt and add a call to scanf() that reads a string into the variable word. For a hint on use of the scanf() function to read a string, see pages 451-453 of the textbook. Add another call to printf() that echoes the characters entered back to the output. Build and test the program.

Add a declaration of an int variable named "length." Then add a while loop that begins at the first character element of word and increments length while (word[length]!=0). Add a statement after the loop that prints the length found. Build and test your program, and verify that the proper length of the word is printed. Add a for loop that reverses the word. This can be accomplished as follows:

Start a loop iterator at the value 0.

Terminate the loop when the iterator is equal to (length+1)/2.

Add a char variable named temp.

In the loop, use the following statements to swap the characters in the string:

temp = word[i];
word[i] = word[length-i-1];
word[length-i-1] = temp;

Be sure to print the reversed word after exiting the for loop!

Build and test your program using at least three test cases. One test case should use a single-letter word such as "a". A second test case should use a word with an even number of letters, such as "even". A third test case should use a word with an odd number of letters, such as "odd".

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Develop a functional c program that implements a design and
Reference No:- TGS0931200

Expected delivery within 24 Hours