A_lemon_D
A_lemon_D
2017-01-03 15:06

学生管理系统,存储和读取问题?

  • c
  • c语言

用qtcreator写的c语言写学生管理系统,可以存储数据,但是读取不了(如图),请问是什么原因?
存储和读取函数代码如下:
void save(void)
{
int i=0;
FILE *f;
char filename[20];
printf("Enter a file name\n");
scanf("%s",&filename);

if((f=fopen(filename,"a+"))==NULL){
    printf("无法打开,文件为空\n");
}
while(i<n)
{
    fprintf(f,"%s%d\n%s%s\n%s%s\n%s%d\n%s%d\n%s%d\n","学号:",p[i].num,"姓名",p[i].name,"性别",p[i].sex,"计算机:",p[i].score[0],"数学:",p[i].score[1],"英语:",p[i].score[2]);
i++;
}
fclose(f);

}

void readStu(void)
{
int i;
FILE *f;
while(!feof(f))
{
fread(&p[i],sizeof(Student),1,f);
i++;
}
fclose(f);
printf("---------------------------\n");
int n;
for(n=0;n<i-1;n++){
printf("%s%d\n%s%s\n%s%s\n%s%d\n%s%d\n%s%d\n","学号:",p[i].num,"姓名",p[i].name,"性别",p[i].sex,"计算机:",p[i].score[0],"数学:",p[i].score[1],"英语:",p[i].score[2]);
}
printf("---------------------------\n");
}图片图片

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答