我调试很久还不知道怎么回事?
#include <stdio.h> #include <string.h>
#include <conio.h>
struct yonghu { /*个人注册信息*/
char name[8];
char sex[4];
char cla[20];
}stud, student[100];
void save()
{ FILE *ip;
if((ip = fopen("student3.txt","a+")) == NULL)
{ printf("不能打开这个文件\n"); return;
}
if(fwrite(&stud,sizeof(struct yonghu),1,ip) != 1)
printf("信息写入错误!"); fprintf(ip,"\n"); fclose(ip);
}
void du()
{
FILE *fp; int i=0,w;
if((fp = fopen("student3.txt","r+")) == NULL)
{ printf("不能打开这个文件\n"); return;
}
while(!fp) {
fread(&student[i],sizeof(struct yonghu),1,fp); i++; }
}
for (d = 0; d <= 14; d++)
{ printf("%s\t%s\t%s",student[d].name[8], student[d].sex[4], student[d].cla[20]);
printf("\n");
}
}
int main()
{
int d;
scanf("%s%s%s", stud.name, stud.sex, stud.cla);
save();
du();
}