当前位置: 代码迷 >> C语言 >> 郁闷的实型数据?(能解释一下吗?)
  详细解决方案

郁闷的实型数据?(能解释一下吗?)

热度:167   发布时间:2005-03-16 10:44:00.0
郁闷的实型数据?(能解释一下吗?)
#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");
}
----------------解决方案--------------------------------------------------------