Ok I figured out the array of strings part. Now I am trying to read in the different values using strtok() like my instructor said. I used a for loop like this:
Code:
for (i = 0; i < count; i++) {
fgets(line, 80, fp);
(*last_name)[i] = strtok(line, ", \n");
(*first_name)[i] = strtok(NULL, ", \n");
(*age)[i] = strtok(NULL, ", \n");
}
However, after this loop I use a simple printf() to check the values for (*last_name)[0], (*first_name)[0], and so on, and none of them are correct. However, when I don't use the for() loop and instead write out each statement separately all the values are what they should be. This works:
Code:
fgets(line, 80, fp);
(*last_name)[0] = strtok(line, ", \n");
(*first_name)[0] = strtok(NULL, ", \n");
(*age)[0] = strtok(NULL, ", \n");
fgets(line, 80, fp);
(*last_name)[1] = strtok(line, ", \n");
(*first_name)[1] = strtok(NULL, ", \n");
(*age)[1] = strtok(NULL, ", \n");
and so on
What's wrong with my loop?