Hey guys im trying to read a file seperated by '|' with 8 fields and 7 '|'
for some reason i cant successfully read a new field which i added menually to the file in the program. Iv tried copying it into the struct but then i get a pointer to integer error am i going about this the correct way?
Code:
struct node
{
int qtyInStock;
}
Code:
/* Read the submenu file line by line, until there is no more to
read */
while(fgets(submenuLine, MAX_SUBMENU_LINE, submenuFileLoad) != NULL)
{
lineNumber++;
submenuToken = strtok(submenuLine, DELIM);
submenuNode = (ItemTypePtr)malloc(sizeof(ItemType));
/* If cannot allocate memory, exit program */
if(submenuNode == NULL)
{
fprintf(stderr, "\nMemory Allocation for item node failed!\n");
fprintf(stderr, "Exiting program...\n");
return EXIT_FAILURE;
}
numTokens = 0;
while(submenuToken != NULL)
{
numTokens++;
/*loading qytInStock for each item*/
if(numTokens == 8)
{
if((strlen(submenuToken) <0 ))
{
printf("Stock levels must be above 0\n");
printf("exiting on error\n");
free(submenuNode);
return EXIT_FAILURE;
}
/*initializing the qtySold array to 0
for small medium and large*/
for(i = 0; i<NUM_PRICES; i++)
{
submenuNode->qtySold[SMALL] = 0;
submenuNode->qtySold[MEDIUM] = 0;
submenuNode->qtySold[LARGE] = 0;
}