I want to read each line into a array. I definitely want to use a struct, but that is unchartered land that I am trying to get familiar with. Here is my code so far
char itemNumber ;
int main ()
int itemAmount = 0;
int timeToFinish = 0;
int elapsedMinutes = 0;
int i = 0;
int readCounter = 0;
int finishTime;//holds the finish items
int counter = 0;
// Prompt the user for a filename.
printf ("Enter a filename to load: ");
scanf ("%s" , &text);
fn = fopen(text, "r");
// Check to make sure that we opened the file successfully.
if (fn != NULL)
//fscanf (fn, "%d", &itemAmount);//Scan first line into variable
// Initialize it to NULLs
for (i=0; i<15; i++)
finishTime[i] = 0;
//Loading each item from the file into our array.
fscanf(fn, "%s %d %d", &itemNumber, &timeToFinish, &elapsedMinutes);
finishTime[counter] = timeToFinish;
//finishTime[counter] = elapsedMinutes;
// Close our file up.
printf ("\nFile successfully loaded!\n");
// Print out the array contents.
for (readCounter = 0; readCounter < 15; readCounter++)
if (finishTime[readCounter] != 0)
printf("item%d %d %d\n", readCounter, finishTime[readCounter]);
// If file failed to open, tell the user.
printf("Error: The file you specified could not be found!");
I have been playing with it for a while, so I figured some outside opinions would be helpful. I have variables itemNumber, timeToFinish, and elapsedMinutes, but I want to connect the struct to the variables and read them in so that I could at any time say I want item4 or item9 and then do with them as I please. Any help for a newb?