Yes, sscanf (line, "lf",f) works well. My new question here is that I want
it to read the data into a point array, but it only reads the first three
numbers from the string in my testing program (code below):
//////////////////////////////////////////
//testing
string line, s;
point a[4];
int n;
file pf;
float b;
pf=fopen("data.txt","r");
line=getline(pf);
printf("%s\n",line);
for(n=0;n<4;n=n+1) {
sscanf(line,"%lf %lf %lf",a[n].x, a[n].y, a[n].z);
printf ("%f %f %f",a[n].x,a[n].y,a[n].z);
printf ("\t n=%d,done!\n", n);
}
fclose(pf);
/////////////////////////////////////////////
The data in my data.txt is:
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0
this is also the value of 'line'. I got the following:
./a.out
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0
1.000000 2.000000 3.000000 n=0,done!
1.000000 2.000000 3.000000 n=1,done!
1.000000 2.000000 3.000000 n=2,done!
1.000000 2.000000 3.000000 n=3,done!
//////////////////////////////////////////
Also if I use fscanf to read from the file:
fscanf(pf,"%lf %lf %lf",a[n].x, a[n].y, a[n].z);
I only get 0.0000000 for all the a[i] values.
Thank you for helping!
Lixia
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Wed Jan 27 2010 - 10:30:02 PST