程序一:
#include
struct point
{
float x;
float y;
}data[2],*pp;
main()
{
FILE *fp;
char ch,*str[1];
int i;
float temp1,temp2;
clrscr();
printf("Input file name:");
scanf("%s",str[0]);
pp = data;
if((fp=fopen(str[0],"rt"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
for(i=0;i<2;i++,pp++)
{
fscanf(fp,"(%f,%f)",&temp1,&temp2);
pp->x = temp1;
pp->y = temp2;
}
pp = data;
for(i=0;i<2;i++,pp++)
printf("Point is (%f,%f)\n",pp->x,pp->y);
fclose(fp);
getch();
}
程序二:
#include
struct point
{
float x;
float y;
}data[2],*pp;
main()
{
FILE *fp;
int i;
char ch,*str[1];
clrscr();
pp = data;
printf("Input file name:");
scanf("%s",str[0]);
if((fp=fopen("d:\\cg\\try\\tpi.txt","rt"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
for(i=0;i<2;i++,pp++)
fscanf(fp,"(%f,%f)",&(pp->x),&(pp->y));
pp = data;
for(i=0;i<2;i++,pp++)
printf("Point is (%f,%f)\n",pp->x,pp->y);
fclose(fp);
getch();
}
程序三:
#include
struct point
{
int x;
int y;
}data[2],*pp;
main()
{
FILE *fp;
int i;
char ch,*str[1];
clrscr();
pp = data;
printf("Input file name:");
scanf("%s",str[0]);
if((fp=fopen("d:\\cg\\try\\tpi.txt","rt"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
for(i=0;i<2;i++,pp++)
fscanf(fp,"(%d,%d)",&(pp->x),&(pp->y));
pp = data;
for(i=0;i<2;i++,pp++)
printf("Point is (%d,%d)\n",pp->x,pp->y);
fclose(fp);
getch();
}
输入文本内容:
(11,12)(13,14)
现象:
程序一,三均运行成功;三错误为scanf: floating point formats not linked/n Abnormal program termination
问题:
为什么间接读入浮点数(程序一),直接读入整型(程序三)均成功,而直接读入浮点数(程序二)失败?
可以具体点吗?网址或直接说明