Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I get an indeterminate amount of inputs from a single line in C, and then put each input into an array? Code below:

How would I get an indeterminate amount of inputs from a single line in C, and then put each input into an array?

Code below:

#include #include

int main() { int L, C; scanf("%d", &L);

char shipName[20+1]; char ships[L][100][20+1]; // array to store ship names for each line int shipCount[L]; // array to store number of ships for each line

// input ship names for each line char line[1000]; for (int i = 0; i < L; i++) { fgets(shipName, 21, stdin); **NEED CODE HERE** }

scanf("%d", &C);

// for each customer, find the ship name for the given week for (int i = 0; i < C; i++) { int w; scanf("%d", &w);

int line = (w - 1) % L; // find the line for the given week int shipIndex = (w - 1) / L; // find the ship index for the given week if (shipIndex < shipCount[line]) { // make sure ship index is within range printf("%s ", ships[line][shipIndex]); } else { printf("None "); } } 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

More Books

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago