C语言编写课题出现问题!!!大家帮忙看一下 指出问题所在
本人编写的是一个职工信息管理系统,但是在显示职工信息过程出现了问题!!!! void add() //添加职工数据
{
FILE *fp; //定义文件
char choice;
struct worker xs;
if((fp=fopen("E:\\worker.txt","ab"))==NULL) {
printf("Can't open file!\n");
exit(0); //打开文件,如果不能打开,就关闭所有文件
}
printf("\n请输入职工的数据:\n");
do{
printf("职工号:");
scanf("%d",&xs.number);
printf("姓名:");
scanf("%s",xs.name);
printf("性别:");
scanf("%s",xs.sex);
printf("年龄: ");
scanf("%d",&xs.age);
printf("学历:");
scanf("%s",xs.study);
printf("工资:");
scanf("%d",&xs.wages);
printf("地址:");
scanf("%s",xs.address);
printf("电话:");
scanf("%d",&xs.telephone);
fwrite(&xs,sizeof(struct worker),1,fp); //将信息写入文件
i++;
printf("Continue(Y/N)?\n");
getchar();
scanf("%c",&choice);
}while((choice=='Y'||choice=='y'));
fclose(fp); //关闭文件
}
void show() // 显示职工数据
{
FILE *fp;
struct worker s;
if((fp=fopen("E:\\worker.txt","rb"))==NULL){
printf("Can't open file!\n");
exit(0);
}
if((fp=fopen("E:\\worker.txt","rb"))==NULL)
{printf("can't open file!\n");
exit(0);}
printf("\n%5s %10s %2s %2s %5s %5s %5s %10s\n","编号","姓名","性别","年龄","学历","工资","地址","电话");
while(!feof(fp))
{
fread(&s,sizeof(worker),1,fp); /*从文件中读取职工信息*/
if(feof(fp)) break; /*判断是否文件尾*/
/*从文件中读取职工信息*/
printf("%5d %10s %2s %2d %5s %5s %5s %10s\n",s.number,s.name,s.sex,s.age,s.study,s.wages,s.address,s.telephone);
}
fclose(fp);
}