#include<stdio.h>
#define SIZE 5
struct student{
long num;
char name[10];
int score[3];
}stu[SIZE];
void save(){
FILE *fp; int i;
if((fp=fopen("C:\\stud.txt","w"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
main(){
int i;
for(i=0;i<SIZE;i++)
scanf("%ld%s%d%d%d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
save();
}
噗_嗤
相关分类