Last post on this topic hopefully.
I think I fixed it.
Check this out.
Code:
struct names{ char name[20][20];
};
Code:
struct names *all = malloc(sizeof(struct names));
if ( (fp = fopen("hw11-data.csv", "r" )) == NULL )
{
printf("Couldn't open file\n");
exit(1);
}
while(fgets(buffer, sizeof(buffer), fp))
{
for(temp = strtok(buffer, ",") ; temp != NULL; temp = strtok(NULL,","))
{
if (strncmp(temp, "MATH", 4) != 0 || strncmp(temp, "CSE", 3) != 0)
strcpy(all[i].name[0], temp);
if (strncmp(temp, "MATH", 4) == 0 || strncmp(temp, "CSE", 3) == 0)
{
k++;
strcpy(all[i].name[k], temp);
}
}
k = 0;
i++;
}
p.s. for some reason when i tried to do else instead of another if statement, it didn't work.