typedef struct item
{
int number;
char package[20];
char start[20];
char finish[20];
int weight;
int distance;
}ITEM;
int i = 0;
int num = 0;
while(fscanf(ifp, "%d %s %s %s %d %d", &item[i].number, item[i].package, item[i].start, item[i].finish, &item[i].weight, &item[i].distance) != EOF)
{
num++;
i++;
}
rewind(ifp);
printf("\n\nnum = %d\n\n", num);
I am trying to read in 6 items and store them into a struct while simultaneously checking to see how many lines there are in a file however when I run this I get a segmentation fault.
The strings do not exceed 10 characters so array size isn't an issue.
I can't replace EOF.