(求助)我的fscanf函数,为什么读入不了文件中的数据
我的“result1.txt”文件里有以下数据(以%8.2f形式输进去的):1.03, 14.01, 16.49, 1.03
48.85, 14.24, 6.96, 1.15
16.74, 18.95, 19.89, 1.03
45.22, 19.97, 3.00, 1.11
程序如下:
#include <stdio.h>
#include <stdlib.h>
main()
{
struct POINT
{ double x;
double y;
double z;
double radius;
};
int i;
struct POINT geo[4];
FILE *fp2;
if((fp2=fopen("result1.txt","r+"))==NULL)
{printf("Cannot open file strike any key exit!");
}
for(i=0;i<4;i++)
{
fscanf(fp2,"%f,%f,%f,%f",&(geo[i].x),&(geo[i].y),&(geo[i].z),&(geo[i].radius));
}
fclose(fp2);
for(i=0;i<4;i++)
{ printf("geo[i]x:%f\n", geo[i].x);
printf("geo[i]y:%f\n", geo[i].y);
printf("geo[i]z:%f\n", geo[i].z);
printf("geo[i]r:%f\n\n", geo[i].radius);
}
}
程序运行的结果是:
geo[i]x:0.000000 0.00
geo[i]y:0.000000 0.00
geo[i]z:0.000000 0.00
geo[i]r:0.000000 0.00
geo[i]x:0.000000 0.00
geo[i]y:0.000000 0.00
geo[i]z:0.000000 0.00
geo[i]r:0.000000 0.00
geo[i]x:0.000000 0.00
geo[i]y:0.000000 0.00
geo[i]z:0.000000 0.00
geo[i]r:0.000000 0.00
geo[i]x:0.000000 0.00
geo[i]y:0.000000 0.00
geo[i]z:0.000000 0.00
geo[i]r:0.000000 0.00
Press any key to continue