fscanf()函数读取数据失败
大家好!有两个文件,一个写入,一个读取。写入成功了,但是读的时候运行崩溃。请帮忙找找问题原因。第一个文件:
#include <stdio.h>
struct student{
int age;
float height;
float weight;
};
int main()
{
struct student stu1={35,163.5,54};
FILE *fp;
fp=fopen("new.dat","a+");
fprintf(fp,"%d %f %f",stu1.age,stu1.height,stu1.weight);
fclose(fp);
return 0;
}
第二个文件:
#include <stdio.h>
struct student{
int age;
float height;
float weight;
};
int main()
{
struct student stu1;
FILE *fp;
fp=fopen("new.dat","r");
fscanf(fp,"%d %f %f",stu1.age,stu1.height,stu1.weight);
fclose(fp);
printf("he is %d years old:",stu1.age);
return 0;
}