So i'm working on a class project that is going to manage a stores inventory. The program will need to remove/add products as well as update stock counts. When the program runs the structure array needs to be initialized by a inventory file that its values are separated by commas which saves all the data after each use.

Here is the file data. 

```
1000,1.49,3.79,10,0,Fish Food
2000,0.29,1.59,100,1,Angelfish
2001,0.09,0.79,200,1,Guppy
5000,2.40,5.95,10,0,Dog Collar (Large)
6000,49.99,129.99,3,1,Dalmatian Puppy

```

Here is the structure layout.

```
    struct inventory_s
    {
      int productNumber;
      float mfrPrice;
      float retailPrice;
      int numInStock;
      char liveInv;
      char productName[PRODUCTNAME_SZ];
    }; 

```

And here is the code

```
int fileData()
{

FILE* pFile;
char *buf = malloc(MAX_INVENTORY); // MAX INVENTORY = 50
char *info;
if ( ( pFile = fopen( "inventory.txt", "r" ) ) == NULL ) //Reading a file
{
    printf( "File could not be opened.\n" );
}

int i = 0;
while (fgets(buf, MAX_INVENTORY, pFile) != NULL)
{
    if ((strlen(buf)>0) && (buf[strlen (buf) - 1] == '\n'))
        buf[strlen (buf) - 1] = '\0';

    info = strtok(buf, ",");
    inventory[i].productNumber = atoi(info);

    info = strtok(buf, ",");
    inventory[i].mfrPrice = atof(info);

     info = strtok(NULL, ",");
    inventory[i].retailPrice = atof(info);

      info = strtok(NULL, ",");
    inventory[i].numInStock = atoi(info);

    info = strtok(NULL, ",");
    strcpy(inventory[i].liveInv, info);

    info = strtok(NULL, ",");
    strcpy(inventory[i].productName, info);

    printf("%i, %f, %f, %i, %s, %s \n", inventory[i].productNumber , inventory[i].mfrPrice, inventory[i].retailPrice , inventory[i].numInStock, inventory[i].liveInv, inventory[i].productName );

    i++;
}

fclose(pFile);
return 0;
}

```

Right now I dont get anything if I run the code, but if I run only up to the first initialization

```
info = strtok(buf, ",");
inventory[i].productNumber = atoi(info);

```

I get all the first values assigned correctly.