I'm back and I 've changed my code around a bit. I almost have it compiling except for one error that says there is a syntax error before inFile my struct that will hold my arrays. It's in the second for loop. I think that I have my struct declared correctly and I think that it will actually hold each line from the text file as an array into my struct. Here's my code

//Struct representing the items in the file
struct inFile 
{
    char itemNumber[32];
    int timeToFinish;
    int elapsedMinutes;
};

typedef struct inFile inFile;

int main ()
{
    char fileName[100];
    int itemAmount = 0;
    char itemNumber[10];
    int timeToFinish = 0;
    int elapsedMinutes = 0;
    int i = 0;
    int readCounter = 0;
    int finishTime[20];//holds the finish items
    int counter = 0;
    
    // Prompt the user for a filename.
    printf ("Enter a filename to load: ");
    scanf ("%s" , &fileName);
    
    FILE *fn;
    fn = fopen(fileName, "r");
    
    // Check to make sure that we opened the file successfully.
    if (fn != NULL) 
    {
        fscanf (fn, "%d", &itemAmount);//Scan first line into variable
                  
        int finishTime[15];          
        // Initialize it to NULLs
        /*
        for (i=0; i<15; i++) 
        {
            finishTime[i] = NULL;
        }
        */
        
        //Loading each item from the file into our array.
        //while (i <= itemAmount)
        for (i=0; i<itemAmount; i++)
        {
                fscanf(fn, "%s, %d, %d,", inFile.itemNumber[i], inFile.timeToFinish[i], inFile.elapsedMinutes[i]);      //HERE I HAVE AN ERROR BEFORE INFILE                        

finishTime[counter] = timeToFinish;
counter++;
                               
        }
        
        //Closes the file
        printf ("\nFile successfully loaded!\n");
        fclose(fn);
                
        // Print out the array contents.
        for (readCounter = 0; readCounter < 15; readCounter++) 
        {
            if (finishTime[readCounter] != 0) 
            {
                printf("item%d %d %d\n", readCounter, finishTime[readCounter]);
            }
        }
    }

    else 
    {
        printf("Error: The file you specified could not be found!");
    }
    
    system ("PAUSE");
    return 0;
}

So frustrated because I'm almost there! Just one little error and a couple of my friends couldn't figure it out either.

struct inFile 
{
    char itemNumber[32];
    int timeToFinish;
    int elapsedMinutes;
};

typedef struct inFile inFile;

You create a structure data type and even typedef but you do not define any variable of type structure for your main to use.

fscanf(fn, "%s, %d, %d,", inFile.itemNumber[i], inFile.timeToFinish[i], inFile.elapsedMinutes[i]);

You are forgetting to use the & with the elements that are of type int and char alone.

char itemNumber[10];
    int timeToFinish = 0;
    int elapsedMinutes = 0;

Those variables have the same identifier names that the elements in the structure declaration.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.