C programming is very finnicky. Here is a short program I wrote:
Code:
#include <stdio.h>
#include <string.h>
int main() {
int one, four, retv;
float two, three;
char line[256];
FILE *in = fopen("test.txt", "r");
while (fgets(line,256,in)) {
retv=sscanf(line,"%d %f %f %d",&one,&two,&three,&four);
printf("%d items read: %d %f %f %d\n",retv,one,two,three,four);
}
return 0;
}
to read a file which looks like this, that I cut n' paste from one of your posts:
Code:
0 0.6 -5 67 1 2005 5 121
1 0 -3.9 75 1 2005 5 121
2 0 -3.9 75 1 2005 5 121
3 0 -3.9 75 1 2005 5 121
4 0 -4 75 1 2005 5 121
Notice there are no column headings in the file, if there are column headings you will have to skip the first line. Anyway, the output is:
4 items read: 0 0.600000 -5.000000 67
4 items read: 1 0.000000 -3.900000 75
4 items read: 2 0.000000 -3.900000 75
4 items read: 3 0.000000 -3.900000 75
4 items read: 4 0.000000 -4.000000 75
-1 items read: 4 0.000000 -4.000000 75
The final line happens when EOF is reached. The reason I used a combination of fgets() and sscanf() instead of fscanf() is because you only want part of each line.
Try this program on your file and see if it works, then we can gradually add what's necessary to put the data into a struct array.