求大神看看问题在哪儿
#include <string.h>#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define N 10000
struct book
{char nam[20],w[30],e[30];
int num,j,k,z;
float p;
}p[N];
struct teacher
{char nam[20],x[20],y[40];
int book,numb,numr;
struct{int year,month,day;}b;
struct{int year,month,day;}r;
}t;
main(void)
{int a(void),b(void),c(void),d(void),e(void),k(void);
int system(cls);
system("graftable 936");
system("cls");
k();
system("pause");
return 0;
}
a(void)
{int i,n,m,j,d,e,s,f;
char q[20],b[20],c[40],S;
FILE *fp,*mp;
printf("\t****************************************\n");
printf("\t****************************************\n");
printf("\t *借阅信息录入* \n");
printf("\t****************************************\n");
printf("\t****************************************\n");
printf("\t *1.借书 \n");
printf("\t****************************************\n");
printf("\t *2.还书 \n");
printf("\t****************************************\n");
printf("\t *3.返回 \n");
printf("\t****************************************\n");
printf(" 请选择菜单序号(以回车结束):");
scanf("%d",&n);
switch(n)
{case 1:clrscr();
if((mp=fopen("图书信息预置2","r"))==NULL)
{printf("无法打开文件!");
exit(0);}
fread(&p[i],sizeof(struct book),1,fp);
fclose(mp);
printf(" *图书借阅* \n");
printf("********************************************************************************\n");
printf("\n请输入教师姓名(以回车结束):");
scanf("%s",&b);
printf("\n请输入教师所属系部(以回车结束):");
scanf("%s",&c);
printf("\n请输入借书日期(年/月/日,以回车结束):");
scanf("%d/%d/%d",&d,&e,&f);
while(1)
{if((fp=fopen("图书信息预置1","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fread(&p[i],sizeof(struct book),1,fp);
fclose(fp);
while(1)
{printf("\n请输入图书编号(以回车结束):");
scanf("%d",&s);
for(i=0;i<m;i++)
if(p[i].num==s)
{printf("\n书名:%s\n",p[i].nam);break;}
if(p[i].num==s) break;
else {clrscr();printf("\n查无此书,请重新输入");}
}
printf("\n库存量:%d\n",p[i].k);
printf("\n作者:%s\n",p[i].w);
printf("\n出版社:%s\n",p[i].e);
printf("\n单价:%.2f\n",p[i].p);
printf("\n请输入借阅数量(以回车结束):");
scanf("%d",&j);
strcpy(t.x,p[i].nam);
t.book=s;
t.numb=j;
p[i].j+=j;
p[i].k-=j;
if((fp=fopen("图书信息预置1","wb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fwrite(&p[i],sizeof(struct book),1,fp);
fclose(fp);
strcpy(t.nam,b);
strcpy(t.y,c);
t.b.year=d;
t.b.month=e;
t.b.day=f;
if((fp=fopen("教师信息","ab"))==NULL)
{printf("无法打开文件!");
exit(0);}
fwrite(&t,sizeof(struct teacher),1,fp);
fclose(fp);
clrscr();
printf("\n请选择是否继续借阅[y/n](以回车结束)\n");
scanf("%s",&S);
if(S=='n')break;
else if(S=='y') clrscr();
else {printf("输入错误,请重新输入\n");
while(1)
{scanf("%s",&S);
if(S=='n'||S=='y'){clrscr();break;}
else printf("输入错误,请重新输入\n");}
}
if(S=='n')break;}
printf("\n借阅完成!");
printf("\n按任意键继续");
getch();
clrscr();
a();
break;
case 2:clrscr();if((mp=fopen("图书信息预置2","r"))==NULL)
{printf("无法打开文件!");
exit(0);}
fscanf(mp,"%d",&m);
fclose(mp);
printf(" *图书归还* \n");
printf("********************************************************************************\n");
printf("\n请输入教师姓名(以回车结束):");
scanf("%s",&b);
printf("\n请输入教师所属系部(以回车结束):");
scanf("%s",&c);
printf("\n请输入还书日期(年/月/日,以回车结束):");
scanf("%d/%d/%d",&d,&e,&f);
while(1)
{if((fp=fopen("图书信息预置1","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fread(&p[i],sizeof(struct book),1,fp);
fclose(fp);
while(1)
{printf("\n请输入图书编号(以回车结束):");
scanf("%d",&s);
for(i=0;i<m;i++)
if(p[i].num==s)
{printf("\n书名:%s\n",p[i].nam);break;}
if(p[i].num==s) break;
else {clrscr();printf("\n查无此书,请重新输入");}
}
printf("\n借阅量:%d\n",p[i].j);
printf("\n作者:%s\n",p[i].w);
printf("\n出版社:%s\n",p[i].e);
printf("\n单价:%.2f\n",p[i].p);
printf("\n请输入归还数量(以回车结束):");
scanf("%d",&j);
strcpy(t.x,p[i].nam);
t.book=s;
t.numr=j;
p[i].j-=j;
p[i].k+=j;
if((fp=fopen("图书信息预置1","wb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fwrite(&p[i],sizeof(struct book),1,fp);
fclose(fp);
strcpy(t.nam,b);
strcpy(t.y,c);
t.r.year=d;
t.r.month=e;
t.r.day=f;
if((fp=fopen("教师信息","ab"))==NULL)
{printf("无法打开文件!");
exit(0);}
fwrite(&t,sizeof(struct teacher),1,fp);
fclose(fp);
clrscr();
printf("\n请选择是否继续归还[y/n](以回车结束)\n");
scanf("%s",&S);
if(S=='n')break;
else if(S=='y') clrscr();
else {printf("输入错误,请重新输入\n");
while(1)
{scanf("%s",&S);
if(S=='n'||S=='y'){clrscr();break;}
else printf("输入错误,请重新输入\n");}
}
if(S=='n')break;}
printf("\n归还完成!");
printf("\n按任意键继续");
getch();
clrscr();
a();
break;
case 3:clrscr();k();break;
default:clrscr();printf("\n****************************************\n");
printf(" 输入错误,请重新输入\n");
printf(" 按任意键继续");
printf("\n****************************************");
getch();
clrscr();
a();
}
}
e(void)
{int i,n=0;
char s;
float f;
FILE *fp,*mp;
if((fp=fopen("图书信息预置1","wb"))==NULL)
{printf("无法打开文件!");
exit(0);}
if((mp=fopen("图书信息预置2","w"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<N;i++)
{clrscr();
n++;
printf(" *图书信息预置* \n");
printf("********************************************************************************");
printf("请输入第%d本书的信息",i+1);
printf("\n请输入图书编号(以回车结束):");
scanf("%d",&p[i].num);
printf("\n请输入书名(以回车结束):");
scanf("%s",&p[i].nam);
printf("\n请输入作者(以回车结束):");
scanf("%s",&p[i].w);
printf("\n请输入出版社(以回车结束):");
scanf("%s",&p[i].e);
printf("\n请输入单价(以回车结束):");
scanf("%f",&f);
p[i].p=f;
printf("\n请输入借阅量(以回车结束):");
scanf("%d",&p[i].j);
printf("\n请输入库存量(以回车结束):");
scanf("%d",&p[i].k);
p[i].z=p[i].k+p[i].j;
printf("\n图书总数:%d\n",p[i].z);
printf("\n请选择是否继续输入(以回车结束)");
printf("\n [y/n]\n");
scanf("%s",&s);
if(s=='n')break;
else if(s=='y');
else {printf("输入错误,请重新输入\n");
while(1)
{scanf("%s",&s);
if(s=='n'||s=='y')break;
else printf("输入错误,请重新输入\n");}
}
if(s=='n')break;
}
for(i=0;i<n;i++)
fwrite(&p[i],sizeof(struct book),1,fp);
fprintf(mp,"%d",n);
fclose(fp);
fclose(mp);
if((fp=fopen("教师信息","wb"))==NULL)
{printf("无法打开文件!");
exit(0);}
fclose(fp);
printf("输入完成!");
printf("\n按任意键返回。");
getch();
clrscr();
k();
}
k(void)
{int n;
printf("\t____________________________________________________________\n");
printf("\t------------------------------------------------------------\n");
printf("\t *欢迎使用图书借阅管理系统* \n");
printf("\t____________________________________________________________\n");
printf("\t------------------------------------------------------------\n");
printf("\t *1.借阅信息录入 \n");
printf("\t------------------------------------------------------------\n");
printf("\t *2.图书信息查询 \n");
printf("\t------------------------------------------------------------\n");
printf("\t *3.挂账信息查询 \n");
printf("\t------------------------------------------------------------\n");
printf("\t *4.借阅信息统计 \n");
printf("\t------------------------------------------------------------\n");
printf("\t *5.图书信息预置 \n");
printf("\t------------------------------------------------------------\n");
printf("\t *6.退出系统 \n");
printf("\t------------------------------------------------------------\n");
printf("\t------------------------------------------------------------\n");
printf("请选择菜单序号(以回车结束):");
scanf("%d",&n);
switch(n)
{case 1:clrscr();a();break;
case 2:clrscr();b();break;
case 3:clrscr();c();break;
case 4:clrscr();d();break;
case 5:clrscr();e();break;
case 6:clrscr();printf("\t--------------------------------------------\n");
printf("欢迎再次使用,再见!\n");
printf("按任意键退出");
printf("\n------------------------------------------------\n");
getch();
exit(0);
default:clrscr();printf("\n-------------------------------------------------\n");
printf(" 输入错误,请重新输入 \n");
printf(" 按任意键继续 ");
printf("\n-------------------------------------------------------------------\n");
getch();
clrscr();
k();}
}
b(void)
{char a[20];
int i,m,n,h,c;
FILE *fp,*mp;
printf("------------------------------------------------------------\n");
printf("------------------------------------------------------------\n");
printf("\t *图书信息查询* \n");
printf("------------------------------------------------------------\n");
printf("------------------------------------------------------------\n");
printf(" *1.按书名查询 \n");
printf("------------------------------------------------------------\n");
printf(" *2.按编号查询 \n");
printf("------------------------------------------------------------\n");
printf(" *3.返回 \n");
printf("------------------------------------------------------------\n");
printf(" 请选择菜单序号(以回车结束):");
scanf("%d",&n);
switch(n)
{case 1:clrscr();
if((mp=fopen("图书信息预置2","r"))==NULL)
{printf("无法打开文件!");
exit(0);}
fscanf(mp,"%d",&m);
fclose(mp);
if((fp=fopen("图书信息预置1","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fread(&p[i],sizeof(struct book),1,fp);
fclose(fp);
if((fp=fopen("教师信息","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
printf(" *图书查询* \n");
printf("********************************************************************************");
while(1)
{printf("请输入图书名(以回车结束):");
scanf("%s",&a);
for(i=0;i<m;i++)
{if(strcmp(p[i].nam,a)==0)
{printf("图书信息\n");
printf("\n图书编号:%d\n",p[i].num);
printf("作者:%s\n",p[i].w);
printf("出版社:%s\n",p[i].e);
printf("单价:%.2f\n",p[i].p);
printf("借阅量:%d\n",p[i].j);
printf("库存量:%d\n",p[i].k);
printf("图书总数:%d\n",p[i].z);
break;}
}
if(strcmp(p[i].nam,a)==0) break;
else {clrscr();printf("\n查无此书,请重新输入\n");}
}
printf("\n借阅信息\n");
while(1)
{if((h=fread(&t,sizeof(struct teacher),1,fp))==1)
{if(strcmp(t.x,a)==0)
{printf("借阅教师姓名:%s\n",t.nam);
printf("所属系部:%s\n",t.y);
printf("借阅数量:%d\n",t.numb);
printf("借阅时间(年/月/日):%d/%d/%d\n",t.b.year,t.b.month,t.b.day);
printf("归还数量:%d\n",t.numr);
printf("归还时间(年/月/日):%d/%d/%d\n",t.r.year,t.r.month,t.r.day);}
}
else break;}
fclose(fp);
printf("查询完成,按任意键返回\n");
getch();
clrscr();
b();
break;
case 2:clrscr();
if((mp=fopen("图书信息预置2","r"))==NULL)
{printf("无法打开文件!");
exit(0);}
fscanf(mp,"%d",&m);
fclose(mp);
if((fp=fopen("图书信息预置1","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
for(i=0;i<m;i++)
fread(&p[i],sizeof(struct book),1,fp);
fclose(fp);
if((fp=fopen("教师信息","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
printf(" *图书查询* \n");
printf("********************************************************************************");
while(1)
{printf("请输入图书编号(以回车结束):");
scanf("%d",&c);
for(i=0;i<m;i++)
{if(p[i].num==c)
{printf("图书信息\n");
printf("\n书名:%s\n",p[i].nam);
printf("作者:%s\n",p[i].w);
printf("出版社:%s\n",p[i].e);
printf("单价:%.2f\n",p[i].p);
printf("借阅量:%d\n",p[i].j);
printf("库存量:%d\n",p[i].k);
printf("图书总数:%d\n",p[i].z);
break;}
}
if(p[i].num==c) break;
else {clrscr();printf("\n查无此书,请重新输入\n");}
}
printf("\n借阅信息\n");
while(1)
{if((h=fread(&t,sizeof(struct teacher),1,fp))==1)
{if(t.book==c)
{printf("借阅教师姓名:%s\n",t.nam);
printf("所属系部:%s\n",t.y);
printf("借阅数量:%d\n",t.numb);
printf("借阅时间(年/月/日):%d/%d/%d\n",t.b.year,t.b.month,t.b.day);
printf("归还数量:%d\n",t.numr);
printf("归还时间(年/月/日):%d/%d/%d\n",t.r.year,t.r.month,t.r.day);}
}
else break;}
fclose(fp);
printf("查询完成,按任意键返回\n");
getch();
clrscr();
b();
break;
case 3:clrscr();k();break;
default:clrscr();printf("\n****************************************\n");
printf("输入错误,请重新输入\n");
printf("按任意键继续");
printf("\n****************************************");
getch();
clrscr();
b();}
}
c(void)
{char a[20],b[40];
int n,h;
FILE *fp;
printf("************************************************************\n");
printf("************************************************************\n");
printf("\t *挂账信息查询* \n");
printf("************************************************************\n");
printf("************************************************************\n");
printf(" *1.个人挂账信息查询 \n");
printf("************************************************************\n");
printf(" *2.系部挂账信息查询 \n");
printf("************************************************************\n");
printf(" *3.返回 \n");
printf("************************************************************\n");
printf(" 请选择菜单序号(以回车结束):");
scanf("%d",&n);
switch(n)
{case 1:clrscr();
if((fp=fopen("教师信息","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
printf(" *个人挂账信息查询* \n");
printf("********************************************************************************");
printf("请输入教师姓名(以回车结束):");
scanf("%s",&a);
printf("个人挂账信息\n");
while(1)
{if((h=fread(&t,sizeof(struct teacher),1,fp))==1)
{if(strcmp(t.nam,a)==0)
{printf("所借图书:%s 借阅数量:%d\n",t.x,t.numb);
printf("借阅时间(年/月/日):%d/%d/%d\n",t.b.year,t.b.month,t.b.day);
if(t.r.year==0)
printf("尚未归还\n");
else {printf("归还数量:%d",t.numr);
printf("归还时间(年/月/日):%d/%d/%d\n",t.r.year,t.r.month,t.r.day);}
if(t.r.year==t.b.year&&(t.r.month-t.b.month)>3)
printf("归还时间超过三个月\n");
else if(t.r.year>t.b.year&&(12-t.b.month+t.r.month)>3)
printf("归还时间超过三个月\n");
}
else break;}
fclose(fp);
printf("查询完成,按任意键返回\n");
getch();
clrscr();
c();
break;
case 2:clrscr();
if((fp=fopen("教师信息","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
printf(" *系部挂账信息查询* \n");
printf("********************************************************************************");
printf("请输入系部名(以回车结束):");
scanf("%s",&b);
printf("系部挂账信息\n");
while(1)
{if((h=fread(&t,sizeof(struct teacher),1,fp))==1)
{if(strcmp(t.y,b)==0)
{printf("教师姓名:%s\n",t.nam);
printf("所借图书:%-25s 借阅数量:%d\n",t.x,t.numb);
printf("借阅时间(年/月/日):%d/%d/%d\n",t.b.year,t.b.month,t.b.day);
if(t.r.year==0)
printf("尚未归还\n");
else {printf("归还数量:%-25d",t.numr);
printf("归还时间(年/月/日):%d/%d/%d\n",t.r.year,t.r.month,t.r.day);}
if(t.r.year==t.b.year&&(t.r.month-t.b.month)>3)
printf("归还时间超过三个月\n");
else if(t.r.year>t.b.year&&(12-t.b.month+t.r.month)>3)
printf("归还时间超过三个月\n");
}
else break;}
fclose(fp);
printf("查询完成,按任意键返回\n");
getch();
clrscr();
c();
break;
case 3:clrscr();k();break;
default:clrscr();printf("\t*****************************************************************\n");
printf(" 输入错误,请重新输入 \n");
printf(" 按任意键继续 ");
printf("\t************************************************************************************");
getch();
clrscr();
k();
}
}
}}
d(void)
{char a[20],b[40],z[20];
int n,g,h,i=0,j=0;
FILE *fp;
printf("\t *借阅信息统计* \n");
printf("***************************************************************************************\n");
printf(" *1.教师借阅信息统计 \n");
printf(" *2.返回 \n");
printf("***************************************************************************************\n");
printf(" 请选择菜单序号(以回车结束):");
scanf("%d",&n);
switch(n)
{case 1:clrscr();
if((fp=fopen("教师信息","rb"))==NULL)
{printf("无法打开文件!");
exit(0);}
printf("请输入教师姓名(以回车结束):");
scanf("%s",&a);
while(1)
{if((h=fread(&t,sizeof(struct teacher),1,fp))==1)
{if(strcmp(t.nam,a)==0)
{i+=t.numb;
j+=t.numr;
strcpy(z,t.y);}
}
else break;}
printf("教师借阅信息统计信息\n");
printf("所属系部:%s\n",z);
printf("借阅图书总数:%d\n",i);
printf("已归还数量:%d\n",j);
printf("尚未归还数量:%d\n",i-j);
fclose(fp);
printf("统计完成,按任意键返回\n");
getch();
clrscr();
d();
break;
break;
case 2:clrscr();k();break;
default:clrscr();printf("\t*******************************************************************\n");
printf(" 输入错误,请重新输入 \n");
printf(" 按任意键继续 ");
printf("\t*************************************************************************************");
getch();
clrscr();
d();}
}