这几行代码为什么不能运行出来?

#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();
}


sunny超1
浏览 1189回答 2
2回答

噗_嗤

不知道题主用的是什么,我这边用VS和VC都能跑,只是有个warn,这在main()之前加个int就可以解决。我猜测是路径问题,修改一下这一句。 if((fp=fopen("C:\\stud.txt","w"))==NULL)                     
打开App,查看更多内容
随时随地看视频慕课网APP