Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started