C语言向二进制文件尾添加结构体

struct student { //学生结构体
char name[LENGTH];
char num[LENGTH];
int chinese;
int math;
int english;
}stu;

void inputScore() //(B)录入学生成绩//
{
FILE *file;
file=fopen("E:\\stu_score.dat","ab");
if(file==FAIL){
printf("File Is Not Exist.\n");
file=fopen("E:\\stu_score.dat","wb+");
printf("File Is Set Up.\n");
file=fopen("E:\\stu_score.dat","ab");
}
printf("Intput name:");
gets(stu.name);
printf("Intput num:");
gets(stu.num);
printf("Intput chinese:");
scanf("%d",&stu.chinese);
printf("Intput math:");
scanf("%d",&stu.math);
printf("Intput english:");
scanf("%d",&stu.english);

fwrite(&stu,sizeof(student),1,file);

fclose(file);
}子函数如图 但是不知道为什么储存不了 求解!!

请看fwrite的用法
size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream);
第一个参数不能为结构体变量
你可以把stu中的变量保存到数组中分别写入
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网