Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I alter this c program so that it stores multiple data input strings from the user into an array, and prints the array's

How can I alter this c program so that it stores multiple data input strings from the user into an array, and prints the array's contents reversed only after done is entered by the user? I am having a difficult time utilizing memory allocation and pointers. Right now the program performs in a way which it takes input lines one by one and prints the reverse immediately after.

image text in transcribed

. WNP X #include #include #define MAXC 50 /* if you need a constant, #define one (or more) */ main.cx 1 2 3 4 5 6 7 8 9 10 11 Fint main(void) { char userText [MAXC]; size_t len = 0; for (;;) { /* loop continually */ fputs ("\Insert the strings you would like reversed: ", stdout); if (!fgets (userText, MAXC, stdin)) /* validate EVERY user-input */ return 1; /* prompt for input (optional) */ 15 16 17 91234998 userText[(len = strcspn (userText, " "))] = 0; /* trim , save den */ if ((len == 1 && *userText == strcmp (userText, "Done") strcmp (userText, "done") return 0; } 'd') IL 1 0) { /* check for 'd' alone */ /* check for "Done" */ /* check for "done" */ == 20 21 22 23 24 25 26 27 28 29 30 31 32 fputs ("reversed: ", stdout); while (len--) putchar (userText[len]); putchar (' '); /* prefix for output (optional) */ /* loop hen times */ /* output char (end-to-start) */ /* tidy up with newline */ } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions