My program should read some segments to id a plane. 3 segments per line. The input archive is:
3 4 25 -4 -30 2 6 7 9 10 3 4
3 4 4 -4 -3 2 6 7 9 10 5 6
and it is read as coordinates: (3, 4) (25, -4) (-30, 2) (6,7) (9,10) (3,4)
A Segment would be a pair of coordinates: S01 - (3,4) (25, -4) and so on
the code:
typedef struct{
int x1, x2;
int y1, y2;
int id;
}Segment;
int main(){
FILE *file;
int i=0, j=0;
Segment *seg;
seg=(Segment*)malloc(500*sizeof(Segment));
file = fopen("input.txt", "r");
while(!feof(file)){
for(i=0; i<3; i++){
fscanf(file, "%d %d %d %d", &seg[j].x1, &seg[j].y1, &seg[j].x2, &seg[j].y2);
seg[j].id=i+1;
printf("%d %d %d %d - ID: %d\n", seg[j].x1, seg[j].y1, seg[j].x2, seg[j].y2, seg[j].id);
j++;
}
}
fclose(file);
return 0;
}
the expected output:
3 4 25 -4 - ID: 1
-30 2 6 7 - ID: 2
9 10 3 4 - ID: 3
3 4 4 -4 - ID: 1
-3 2 6 7 - ID: 2
9 10 5 6 - ID: 3
The output it gives me, I do not know why:
3 4 25 -4 - ID: 1
-30 2 6 7 - ID: 2
9 10 3 4 - ID: 3
3 4 4 -4 - ID: 1
-3 2 6 7 - ID: 2
9 10 5 6 - ID: 3
0 0 0 0 - ID: 1
0 0 0 0 - ID: 2
0 0 0 0 - ID: 3
I know this must be some silly mistake, but any ideas of what is causing it?! Thanks in advance :)