郁闷的实型数据?(能解释一下吗?)
#include "stdio.h"#define size 100
struct student
{float num;
}stud[size];
main()
{int i;
FILE *fp;
for (i=0;i<size;i++)
scanf("%f",&stud[i].num);
if ((fp=fopen("t1_dat","wb"))==NULL)
{printf("cannot open file\n");
exit(0);
}
for (i=0;i<size;i++)
if (fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
printf("file writer error\n");
}
程序运行后提示:scanf:float point formats not linked abormal program termination
为什么呢?怎么改才能将实行数据写入文件中呢?
谢了!
----------------解决方案--------------------------------------------------------
为什么要定义这样的结构体?就一个域?
#include "stdio.h"
#define size 100
struct student
{float num;
}stud[size];
main()
{int i;float f;
FILE *fp;
for (i=0;i<size;i++)
{ scanf("%f",&f); stud[i].num=f;}
if ((fp=fopen("t1_dat","wb"))==NULL)
{printf("cannot open file\n");
exit(0);
}
for (i=0;i<size;i++)
if (fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
printf("file writer error\n");
}
----------------解决方案--------------------------------------------------------