I\'m trying to use fgets and strtok() to read in a file line by line, and create a linked list of each different line of information.
Right now, I\'m only just putt
strtok()
returns pointers inside line[]
so when you read the next line all the pointers you saved are now pointing to places where the last line of the file is stored.
You could allocate memory for each bit of string like so:
//load last name
value = strtok(line, ",");
result[i][0] = malloc(strlen(value) + 1);
strcpy(result[i][0], value);
As an aside, you don't need the loops at the start to set everything to NULL
, you could do this instead:
char *result[10][4] = {0};