我是个菜鸟,但是遇到了一个问题,我简单说明一下我在D盘下自己用记事本写了一个文件其中的一部分是这样的
zhang 5 15 1.65 90.5
wang 3 10 1.50 80.0
我在TC下用fscanf读取数据是这样的
int i;
student stu[2];
for(i=0;i<2;i++)
fscanf("%s %d %d %f %f\n",stu.name,&(stu[i].number),&(stu[i].age),&(stu[i].height),&(stu[i].score));
其中student是如下的一个结构体:
typedef struct
{
  char name[20];
  int number;
  int age;
  float height;
  float score;
}student;
结果读取出来的数据到浮点型哪里就出错了,比如读出的是
zhang 5 15 0.000 0.000
1.65 90 0 0.000 0.000
wang 3 10 0.000 0.000
1.50 80 0 0.000 0.000
此数据前面还有一堆不知道是什么的浮点型数据
如果哪位高手肯抽时间帮帮小弟,小弟将不胜感激!

解决方案 »

  1.   

    long double呢?
    %s %d %d %lg %lg
      

  2.   

    不行啊,运行后显示scanf:floating point formats not linked
    Abnormal program termination
      

  3.   

    typedef struct
    {
    char name[20];
    int number;
    int age;
    float height;
    float score;
    }student;
    int i;
    student stu[2];
    FILE *fp=fopen("D:\\a.txt","rb");
    for(i=0;i<2;i++)
    fscanf(fp,"%s %d %d %f %f",(stu[i].name),&(stu[i].number),
    &(stu[i].age),&(stu[i].height),&(stu[i].score));
    fclose(fp);
      

  4.   

    你只有显示的代码啊,你怎么读取赋值的呢??
    stu.name 这个是笔误??