#include<stdio.h>#define SIZE 5struct 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();}
2 回答

噗_嗤
TA貢獻1條經(jīng)驗 獲得超0個贊
不知道題主用的是什么,我這邊用VS和VC都能跑,只是有個warn,這在main()之前加個int就可以解決。我猜測是路徑問題,修改一下這一句。
?if((fp=fopen("C:\\stud.txt","w"))==NULL)
? ? ? ? ? ? ? ? ? ? ?
點擊展開后面1條
- 2 回答
- 0 關(guān)注
- 1249 瀏覽
添加回答
舉報
0/150
提交
取消