Question: Write an ANSI-C program that reads user input strings line by line, until a line of xxx is entered. The program then outputs the inputs

Write an ANSI-C program that reads user input strings line by line, until a line of xxx is entered. The program then outputs the inputs after reordering the first 6 rows of inputs.

Assume that there are no more than 30 lines of inputs, and also assume that there are at least 6 lines of inputs. Assume that each line contains no more than 50 characters. Note: each line of input may contain spaces. use fgets(.., 50, stdin) to read in a line. Note that a trailing is also read in. use a 2D array to store the user inputs. That is, similar to lab4, define something like records[30][50] when all the inputs have been read in (indicated by xxx), exchange row 0 and row 1 in main(), and then send the array to a function exchange() to exchange some other rows. define a function void exchange(char[][50])which takes as argument an 2D array, and swaps the record in row 2 with that in row 3, and swaps row 4 with the row 5. Assuming the array has at least 6 rows. define a function void printArray(char[][50], int n)which takes as argument an 2D array, and then prints the first n rows of the records on stdout. Use this function in main to display all the rows of the array

Sample OUTPUT:

Write an ANSI-C program that reads user input strings line by line,

until a line of xxx is entered. The program then outputs the

indigo 329 % a.out Enter string: this is input 0, orange is orange Enter string: this is input 1, apple is greern Enter string: this is input 2, cherry is red Enter string: this is input 3, banana is yellow Enter string: this is input 4, do you like them? Enter string: this is input 5, yes bye Enter string: this is input 6, bye Enter string: xxx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!