I'm trying to read a series of txt files filled of intergers and double data,but in each file I have the first line as shown:
X Y
1 67.944 3.796
2 265.140 5.380
3 233.250 5.667
4 512.333 6.100
5 585.611 6.019
6 98.674 7.065
7 155 6
8 308 6.583
9 496.357 6.714
10 533.242 8.113
11 479.679 9.071
12 623 9.286
13 16.224 9.914
14 280.420 9.700
15 206.750 11.833
16 248.308 12.308
17 83.940 13.100
18 324 12.583
19 369.056 13.204
20 445.286 13
21 140.900 13.460
22 168.278 13.833
23 401.143 14.036
so as you can see I have this slash and XY written in each file with 3 coloumns,I'm trying to read it with the following code I'm not able:
/* reading the data from the measurement file */
for(line=0;line< 1260;line++)
{
if(line == 0)
fscanf(measure_file,"%*d\n");
else
fscanf(measure_file,"%d\t%le\t%le\n",&n[line],&x[line],&y[line]);
}
maybe I'm doing something wrong in if(line == 0) fscanf(measure_file,"%*d\\n"); anyone can help please ??
Try this:
char header[30];
fgets(header, sizeof(header), measure_file);
for(line=0;line< 1260;line++) {
if (fscanf(measure_file, "%d\t%le\t%le\n", &n[line], &x[line], &y[line]) != 3)
break;
// ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.