#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)
struct student
{
char name[50];
int id;
float english_score;
float physics_score;
float c_score;
};
int main()
{
FILE *fp;
int i;
struct student s_data;
fp = fopen("student.dat", "w");
if (fp == NULL) {
printf("File cannot be opened\n");
exit(0);
}
for (i = 0; i < 3; i++)
{
printf("请输入学生信息 %d (学号, 姓名, 英语成绩,物理成绩,C语言程序设计成绩): ", i + 1);
scanf("%d %s %f %f %f", &s_data.id, s_data.name, &s_data.english_score, &s_data.physics_score, &s_data.c_score);
fwrite(&s_data, sizeof(struct student), 1, fp);
}
fclose(fp);
fp = fopen("student.dat", "r");
if (fp == NULL) {
printf("File cannot be opened\n");
exit(0);
}
printf("学生信息:\n");
while (fread(&s_data, sizeof(struct student), 1, fp) == 1) {
printf("学号: %d, 姓名: %s, 英语成绩: %.1f, 物理成绩: %.f, C语言程序设计成绩: %.f\n", s_data.id, s_data.name, s_data.english_score, s_data.physics_score, s_data.c_score);
}
fclose(fp);
return 0;
}
这个程序怎么追加到文本文件stud.txt