急需用C语言写的图书馆信息管理系统

一、设计任务
请设计一个图书馆信息管理系统。通过该系统,可以方便查询图书馆中的图书信息(ID号(图书编号),图书名字,出版社,图书数量,图书作者,图书价格等)。
二、设计要求
1、基本要求
1.根据ID号查询图书信息;
2.根据图书名字查询图书信息;
3.显示系统中所有图书信息;
4.往系统中添加一个图书信息;
5.从系统中删除一个图书信息;
6.程序退出时将系统中所有图书信息保存到文件中;
7.程序启动时将文件中所有图书信息读入程序中。
2、扩展要求
1.系统中所有图书按ID号排序;
2.系统中所有图书按价格排序;
3.按图书出版社,分类显示系统中的图书信息;
6. 自己设计一些合理的附加功能。

第1个回答  2009-07-10
功能描述:
(1)新进图书基本信息的输入。
(2) 图书基本信息的查询。
(3) 对撤消图书信息的删除。
(4)为借书人办理注册。
(5)办理借书手续(非注册会员不能借书)。
(6)办理还书手续
信息描述:有关该系统基本信息的描述,如:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等
#include "stdio.h"
#include<graphics.h>
#include "conio.h"
#include<stdlib.h>
#include<string.h>

void main()
{void adm1(),adm2(),build(),huan(),borrow(),dele();
adm1();

}

void adm1()
{ FILE *fp,*p ;
char adp[20],password[20];
int i,n=0;
textbackground(2);
clrscr();
gotoxy(25,12);
fp=fopen("pass","r");
if(fp==NULL) { printf("no exit ");getch();exit(0);}
printf("input password:");
for(;;)
{

window(42,12,53,12);
textbackground(0);
clrscr();
gets(adp);
for(i=0;adp[i]!='\0';i++);
fgets(password,i+1,fp);
gotoxy(55,12);
if(strcmp(password,adp)==0) { window(55,12,70,12);clrscr();cprintf("YES");getch();adm2();getch();exit(0);}
else{ n++;
window(55,12,60,12);clrscr();gotoxy(55,12);cprintf("error");
for(i=0;i<30;i++) delay(8000);
if(n==2) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("once again");for(i=0;i<=30;i++) delay(8000);}
if(n==3) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("3 second out");for(i=0;i<=30;i++) { delay(8000);}
exit(0);
}
}
fclose(fp);clrscr();

}
}
void adm2()
{ char a;
window(1,1,80,25);
clrscr();
for(;;)
{ clrscr();
gotoxy(30,8);printf("built a new user (B)");
gotoxy(30,10);printf("return book (R)");
gotoxy(30,12);printf("borrow books (J)");
gotoxy(30,14);printf("delete user (D)");
a=getch();
if(a=='b') build();
if(a=='r') huan();
if(a=='j') borrow();
if(a=='d') dele();
else continue;

}

}

void build()
{ FILE *f,*p;
char id[20],name[20],sex[2],age[3],grad[50];
window(1,1,80,25);
clrscr();
printf("ID number:");
scanf("%s",id);
printf("name:");
scanf("%s",name);
printf("sex:");
scanf("%s",sex);
printf("grad:");
scanf("%s",grad);
p=fopen(id,"w+");
if(p==NULL) { printf("can't build that user");getch();adm2();}

fprintf(p,"%s ",name);
fprintf(p,"%s ",id);
fprintf(p,"%s ",sex);
fprintf(p,"%s ",grad);
printf("bulid success");
getch();
fclose(p);
}

void huan()
{
FILE *fp,*p,*f;
char id[20],a[5][50],name[20],c;
int i=0,m,k; clrscr();
printf("input ID number:");
scanf("%s",id);
p=fopen(id,"r");
if(p==NULL) { printf("error");getch();fclose(p);exit(0);}
fscanf(p,"%s",name);
fclose(p);
fp=fopen(name,"r");
do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));

for(k=0;k<i-1;k++) printf("\nbook %d: %s",k+1,a[k]);
fclose(fp);
f=fopen(name,"w+");
for(;;)
{
printf("\n\npress the book number that you want to return. \n\nPress 6 if you want to return all. \n\npress 7 to cancle.\n");
scanf("%d",&m);
if(m==7) { for(k=0;k<i-1;k++)
{
fprintf(f,"%s\n",a[k]);
}
fclose(f);
adm2();
}
if(m==6) remove(name);
if(m<6)
for(k=0;k<i-1;k++)
{ if(k!=m-1)
fprintf(f,"%s\n",a[k]);
}
printf("book %d has returned.",m);
printf("\ncontinue? (Y/N)");
c=getch();
if(c=='y') continue;
if(c=='n') { fclose(f);adm2(); }
}
}

void borrow()
{ FILE *f,*m,*p;
char id[20],book[5][50],name[20],c;
int i=0,n=0,k;
window(1,1,80,25);clrscr();
printf("please input the user's ID:");
scanf("%s",id);
m=fopen(id,"r");
if(m==NULL) { printf("user no exit"); getch();fclose(m);adm2();}
fscanf(m,"%s",name);
fclose(m);
p=fopen(name,"r");
if(p==NULL);
else
{ while(!feof(p))
{
fscanf(p,"%s",book[i]);
i++;
}
i--;
for(k=0;k<i;k++) printf("\nbook %d :%s",k+1,book[k]);
}
fclose(p);
f=fopen(name,"w");
printf("\nhow many book do you want to borrow?:");
do{printf("\ninput:");scanf("%d",&n); }while(i+n>=6);
for(k=i;k<i+n;k++)
{ printf("\nbook %d :",k+1);
scanf("%s",book[k]);
}
for(k=0;k<i+n;k++) fprintf(f,"%s\n",book[k]);
fputc('\0',f);
printf("success");
fclose(f);

}

void dele()
{ FILE *fp,*f;
char id[20],a[4][20],c,b[5][50];
int i=0,j=0,k;
window(1,1,80,25);clrscr();
printf("Input ID number:");
scanf("%s",id);
fp=fopen(id,"r");
if(fp==NULL) { printf("\nuser isn't exit");getch(); fclose(fp);adm2();}
else while(!feof(fp))
{ fscanf(fp,"%s",a[i++]);}
printf("\nname: %s",a[0]);
printf("\nID: %s",a[1]);
printf("\nsex: %s",a[2]);
printf("\ngrad: %s",a[3]);
f=fopen(a[0],"r");
if(f==NULL);
else {
while(!feof(f))
{ fscanf(f,"%s",b[j++]);}
for(k=0;k<j-1;k++) printf("\nbook %d: %s",k+1,b[k]);
}
printf("\nDo you want to delete? (Y/N): ");
c=getch();
fclose(fp);
fclose(f);
if(c=='y') { remove(id);remove(a[0]);printf("\nsuccess");getch();adm2();}
if(c=='n') adm2();
}
第2个回答  2009-07-04
我这有一个源代码,大家分享下吧!希望对你有帮助......
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "string.h"
#include "math.h"
#define LEN sizeof(struct library)
#define LEN1 sizeof(struct reader)
#define NULL 0
struct library//图书馆结构体
{int shuhao,xcl;
char name[20],author[20],chuban[20];
struct library *next;
};

struct reader//读者结构体
{
int zhenghao;
char mingzi[20],riqi[20],zname[20];
struct reader *next;
};

void mainmenu() //显示主菜单
{ system ("cls");
printf("********************************************************************************");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("\t\t\t\t 1.图书馆信息\n\n");
printf("\t\t\t\t 2.借阅系统\n\n");
printf("\t\t\t\t 3.退出系统\n\n");
printf("\t\t\t 请按键选择,回车确定\n");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("********************************************************************************");
return ;
}

void menu1() //显示图书馆信息菜单
{ system ("cls");
printf("********************************************************************************");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("\t\t\t\t 1.采编入库\n\n");
printf("\t\t\t\t 2.清除库存\n\n");
printf("\t\t\t\t 3.图书查询\n\n");
printf("\t\t\t\t 4.库存一览\n\n");
printf("\t\t\t\t 5.返回上一层\n\n");
printf("\t\t\t 请按键选择,回车确定\n");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("********************************************************************************");
return ;
}
void menu2() //显示查询菜单
{ system ("cls");
printf("********************************************************************************");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("\t\t\t\t 1.书号查询\n\n");
printf("\t\t\t\t 2.书名查询\n\n");
printf("\t\t\t\t 3.作者查询\n\n");
printf("\t\t\t\t 4.出版社查询\n\n");
printf("\t\t\t 请按键选择,回车确定\n");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("********************************************************************************");
return ;
}
void main()//主函数,调用main1
{void main1();
main1();}

void main1()//main1函数
{void tsgxx();//声明
void jieshuxitong();//声明
char choose;
mainmenu();
scanf("%c",&choose);
switch(choose)//功能函数选择
{ case '1':tsgxx();break;
case '2':jieshuxitong();break;
case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;
}
}

void tsgxx()//图书馆信息函数
{ void tsjinku();
void shanchu();
void chaxunts();
void xianshikucun();//函数声明
char choose;
menu1();//调用菜单函数
scanf("%c",&choose);
scanf("%c",&choose);
for (;;)
switch(choose)//功能函数选择
{ case '1':tsjinku();break;
case '2':shanchu();break;
case '3':chaxunts();break;
case '4':xianshikucun();break;
case '5':main1();break;
}
}

int tjzs()//统计文本个数函数
{ FILE *fp;
int tshuhao=0,txcl=0,n;
char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'};
fp=fopen("library.txt","r");//打开文件
for (n=0;!feof(fp);n++)//逐个读文件
fscanf(fp,"%d %s %s %s %d",&tshuhao,tname,tauthor,tchuban,&txcl);
n--;
fclose(fp);//关闭文件
return (n);//返回个数
}

int tjdzzs()//统计文本个数函数
{ FILE *fp;
int zhenghao=0,n;
char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};
fp=fopen("reader.txt","r");//打开文件
for (n=0;!feof(fp);n++)//逐个读文件
fscanf(fp,"%d %s %s %s ",&zhenghao,&mingzi,&riqi,&zname);
fclose(fp);//关闭文件
return (n);//返回个数
}

void tsjinku()//图书进库函数
{ FILE *fp;
int shuhao=0,xcl=0,n=0;
char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};
char hitkey;
system ("cls");
if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件,不存在此文件则新建
{ fp=fopen("library.txt","w");
fclose(fp);
}
fp=fopen("library.txt","a");
printf("\n\n\n\n\n\n\t\t\t请按以下格式输入图书信息:\t\t\t\t\t\t 书号 书名 作者 出版社 进库量\n请输入:");//按格式输入图书馆信息
for (;hitkey!=27;)//循环输入
{ if (n!=0)
printf("请输入:");
scanf("%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);
fprintf(fp,"%d %s %s %s %d\n",shuhao,name,author,chuban,xcl);
printf("继续输入请按回车,结束输入请按esc\n");
n++;
hitkey=getch();
for (;hitkey!=13&&hitkey!=27;)
hitkey=getch();
}
fclose(fp);
printf("\n\n\n\n\n\n\t\t\t保存成功,按任意键返回上一层!");
getch();
tsgxx();//返回上一层
}

void shanchu()//删除图书信息函数
{ struct library *head=NULL;
struct library *p,*p1,*p2;
int tshuhao=0,txcl=0,n=0,j,i;
char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};
char hitkey;
FILE *fp;
if ((fp=fopen("library.txt","r"))==NULL)//打开文件
{ system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");
getch();
tsgxx();
}
else
{ system ("cls");
printf("\n\n\n\n\n\n\n\n\t\t请输入你要删除的书名:");//输入删除图书书名
scanf("%s",&ttname);
printf("\t\t确认删除请回车,取消请按esc\n");
hitkey=getch();
for (;hitkey!=13&&hitkey!=27;)
hitkey=getch();
if (hitkey==27)
tsgxx();
fp=fopen("library.txt","r");
for (j=0;!feof(fp);)//读文件夹信息,统计个数
{ j++;
fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);
}
fclose(fp);
fp=fopen("library.txt","r");
for (i=1;i<j;i++)
{ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);
if (strcmp(ttname,tname))//比较名字,将不同名字的信息复制到链表
{ n++;
if (n==1)//建立链表
{ p1=p2=(struct library*)malloc(LEN);
head=p1;
}
else
{ p2->next=p1;
p2=p1;
p1=(struct library*)malloc(LEN);//新建链表
}
p1->shuhao=tshuhao;//复制书号
strcpy(p1->name,tname);//复制书名
strcpy(p1->author,tauthor);//复制作者名子
strcpy(p1->chuban,tchuban);//复制出版社
p1->xcl=txcl;//复制个数
}
}
if (n==0)
{ head=NULL;
}
else
{
p2->next=p1;
p1->next=NULL;
fclose(fp);
}
}
fp=fopen("library.txt","w");//清空文件
fclose(fp);
fp=fopen("library.txt","a");//追加文件
p=head;
for (;p!=NULL;)//把链表内容覆盖到文件
{
fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);
p=p->next;
}
fclose(fp);//关闭文件
system ("cls");
printf("\n\n\n\n\n\n\n\n\t\t 删除成功 \n\t\t按任意键返回上一层\n");
getch();//返回上一层
tsgxx();
}

void chaxunts()//查询函数
{
FILE *fp;
char choose;
int ttshuhao=0,tshuhao=0,txcl=0,n=0,k=0,i,l;
char tname[20]={'\0'},ttauthor[20]={'\0'},tauthor[20]={'\0'},ttchuban[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};
if ((fp=fopen("library.txt","r"))==NULL)//打开文件
{ system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");
getch();
tsgxx();
}
l=tjzs();//获得文件个数
menu2();//调用菜单函数
scanf("%c",&choose);scanf("%c",&choose);//选择查询方式
if (choose=='5')
return;
else if (choose=='1')//书号查询
{ system ("cls");
printf("请输入书号:");
scanf("%d",&ttshuhao);
}
else
if (choose=='2')//书名查询
{ system ("cls");
printf("请输入书名:");
scanf("%s",ttname);
}
else
if (choose=='3')//作者查询
{ system ("cls");
printf("请输入作者:");
scanf("%s",ttauthor);
}
else
if (choose=='4')//出版社查询
{ system ("cls");
printf("请输入出版社:");
scanf("%s",ttchuban);
}
system ("cls");
for (i=0;i<l;i++)
{ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读文件信息
if (ttshuhao==tshuhao||!strcmp(ttname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttchuban,tchuban))//输出查询信息
{
if (k==0)
{
printf("\t\t\t\t查询结果:\n\n");
printf("\t 书号 书名 作者 出版社 现存量 \n");
}
printf("\t %-4d %-8s %-8s %-8s %-4d \n",tshuhao,tname,tauthor,tchuban,txcl);
k++;
}
}
if (k==0)//文件夹为空则输出无记录
{ system ("cls");
printf("\n\n\n\n\n\n\n\t\t\t\t无符合记录!\n");
getch();
tsgxx();
}
fclose(fp);
getch();//返回
tsgxx();
}

void xianshikucun()//现实库存信息
{
FILE *fp;
int shuhao=0,xcl=0,n=0,i=0,j=0;
char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};
if ((fp=fopen("library.txt","r"))==NULL)//打开文件夹
{
system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");
}
n= tjzs();
if (n==0)
{ system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");
}
fp=fopen("library.txt","r");
system ("cls");
printf("********************************************************************************");
printf("\t 书号 书名 作者 出版社 库存量 \n");
printf("********************************************************************************");
for (i=0;i<n;i++)//输出信息
{
fscanf(fp,"%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);
printf("\t %-4d %-8s %-8s %-8s %-4d \n",shuhao,name,author,chuban,xcl);
}
fclose(fp);
printf("\t\t\t\t按任意键返回\n");
getch();//返回
tsgxx();
}

void menu3() //显示借书系统主菜单
{ system ("cls");
printf("********************************************************************************");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("\t\t\t\t 1.借书登记\n\n");
printf("\t\t\t\t 2.还书登记\n\n");
printf("\t\t\t\t 3.借阅情况查看\n\n");
printf("\t\t\t\t 4.返回上一层\n\n");
printf("\t\t\t 请按键选择,回车确定\n");
printf("*^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^*");
printf("********************************************************************************");
return ;
}

void jieshuxitong()//借书系统函数
{ void jieshu();
void huanshu();
void duzheyilang();//函数声明
char choose;
menu3();
scanf("%c",&choose);
scanf("%c",&choose);//选择功能
for (;;)
switch(choose)//调用函数
{ case '1':jieshu();break;
case '2':huanshu();break;
case '3':duzheyilang();break;
case '4':main1();break;
}
}

void jieshu()//借书函数
{
FILE *fp,*fp3;
struct library *head=NULL;
struct library *p,*p1,*p2;
int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;
char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};
char hitkey=0;
system ("cls");
{
if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件
{
system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t 图书馆无库存!按任意键退出!");
getch();
exit (0);
}
else
{
{
printf("\n\n\n\n\n\n\t\t\t请输入借阅书名:\t\t\t\t\t\t \n请输入:");//输入书名
scanf("%s",zname);
k= tjzs();//统计图书馆文件个数
for (i=0;i<k;i++)//读入图书馆信息,存储到链表
{
fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);
n++;
if (n==1)
{ p1=p2=(struct library*)malloc(LEN);
head=p1;
}
else
{ p2->next=p1;
p2=p1;
p1=(struct library*)malloc(LEN);//新建链表
}
p1->shuhao=tshuhao;//复制书号
strcpy(p1->name,tname);//复制书名
strcpy(p1->author,tauthor);//复制作者
strcpy(p1->chuban,tchuban);//复制出版社
p1->xcl=txcl;//复制现存量
}
if (n==0)
head=NULL;
else
{
p2->next=p1;
p1->next=NULL;
fclose(fp);
}
}
}
p=head;
for (;p!=NULL;)//读链表
{
if(!(strcmp(p->name,zname)))//名字相同
{flag=1;//标记取1
loop=p->xcl;//现存量减1
(p->xcl)--;}
p=p->next;
}
if(flag&&(loop>0))//存在借书书名且现存量大于0
{ fp=fopen("library.txt","w");
fclose(fp);
fp=fopen("library.txt","a");
p=head;
for (;p!=NULL;)
{
fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);
p=p->next;
}
free(p);//把链表内容覆盖文件
fclose(fp);}
if(flag&&(loop>0))//存在借书书名且现存量大于0
{
{
if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文件夹
{ fp3=fopen("reader.txt","w");
fclose(fp3);
}
fp3=fopen("reader.txt","a");
}

{
{ if (n!=0)

printf("\n\n\n\n\n\n\t\t\t请按以下格式输入读者信息:\t\t\t\t\t\t 证号 姓名 归还日期 借书书名\n请输入:");//录入读者信息
scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);
fprintf(fp3,"%d %s %s %s \n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);
fp=fopen("library.txt","w");//删除图书馆文件信息
fclose(fp);
fp=fopen("library.txt","a");//重新追加信息
p=head;
for (;p!=NULL;)//把链表内容覆盖图书馆文件
{

fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);
p=p->next;
}
fclose(fp);
fclose(fp3);
printf("成功!按任意键返回\n");
getch();//返回
jieshuxitong();
}
}

jieshuxitong();
}
else
printf("此书已被借完!按任意键返回!");//否则输出此书已被接完
getch();//返回
jieshuxitong();
}
}

void huanshu()//还书函数
{FILE *fp,*fp3;
struct reader *head=NULL;
struct reader *p,*p1,*p2;
struct library *lhead1=NULL;
struct library *zp1,*lp1,*lp2;
int tshuhao=0,txcl=0,i;
char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};
int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;
char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};
char hitkey=0;
system ("cls");
{
if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文件,则输出不能还书
{
system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t 不存在借书者!按任意键退出!");
getch();
exit (0);
}

else
{
{
printf("\n\n\n\n\n\n\t\t\t请输入读者证号和书名:\t\t\t\t\t\t \n请输入:");
scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名
k= tjdzzs();//获取读者文件夹信息个数
for (i=0;i<k;i++)//读取读者文件夹信息
{
fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);
if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//如果证号书名存在,则标记为1
flag=1;
}
fclose(fp);
fp=fopen("reader.txt","r");//打开读者文件
if(flag)
{
for (i=0;i<k;i++)//将读者文件复制到链表
{
fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//读取文件信息
if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname)))
{ n++;
if (n==1)
{ p1=p2=(struct reader*)malloc(LEN1);//新建链表
head=p1;
}
else
{ p2->next=p1;
p2=p1;
p1=(struct reader*)malloc(LEN1);//新建链表
}
p1->zhenghao=tzhenghao;//复制证号
strcpy(p1->mingzi,tmingzi);//复制读者名字
strcpy(p1->riqi,triqi);//复制日期
strcpy(p1->zname,tzname);//复制书名
}
}
if (n==0)
head=NULL;
else
{
p2->next=p1;
p1->next=NULL;
fclose(fp);
}
fp=fopen("reader.txt","w");//清空读者文件
fclose(fp);
fp=fopen("reader.txt","a");//追加信息
p=head;
for (;p!=NULL;)//把链表内容覆盖读者文件
{
fprintf(fp,"%d %s %s %s \n",p->zhenghao,p->mingzi,p->riqi,p->zname);
p=p->next;
}
free(p);
fclose(fp);
}
}
}
}
if(flag)//标记为1,既还书时
{
{
{printf("确认还书请按回车!");
for (;hitkey!=13&&hitkey!=27;)
hitkey=getch();
if (hitkey==13)
printf("成功!按任意键返回!");
n=0;flag=0;
fp3=fopen("library.txt","r");//打开图书馆文件
k= tjzs();//获取图书馆文件个数
for (i=0;i<k;i++)//将图书馆文件复制到链表
{
fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息
n++;
if (n==1)
{ lp1=lp2=(struct library*)malloc(LEN);//新建链表
lhead1=lp1;
}
else
{ lp2->next=lp1;
lp2=lp1;
lp1=(struct library*)malloc(LEN);//新建链表
}
lp1->shuhao=tshuhao;//复制书号
strcpy(lp1->name,tname);//复制书名
strcpy(lp1->author,tauthor);//复制作者
strcpy(lp1->chuban,tchuban);//复制出版社
lp1->xcl=txcl; //复制现存量
}
if (n==0)
{ lhead1=NULL;
}
else
{
lp2->next=lp1;
lp1->next=NULL;
fclose(fp3);
}
}
}
zp1=lhead1;
for (;zp1!=NULL;)
{
if(!(strcmp(zp1->name,ttzname)))//寻找书名相同
++(zp1->xcl);//现存量加1
zp1=zp1->next;
}
fp3=fopen("library.txt","w");//清空图书馆文件
fclose(fp);
fp3=fopen("library.txt","a");//追加信息
zp1=lhead1;
for (;zp1!=NULL;)//把链表内容覆盖图书馆文件
{
fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息
zp1=zp1->next;
}
fclose(fp3);
getch();//返回
jieshuxitong();
}
else
printf("不存在此信息!按任意键返回!");
getch();//返回
jieshuxitong();
}

void duzheyilang()//显示借书情况函数
{
FILE *fp;
int zhenghao=0,xcl=0,n=0,i=0,j=0;
char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};
if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文件夹
{
system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");
}
n=tjdzzs();
if (n==0)
{ system ("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");
}
fp=fopen("reader.txt","r");
system ("cls");
printf("********************************************************************************");
printf("\t 证号 读者姓名 还书日期 书名 \n");
printf("********************************************************************************");
for (i=0;i<n;i++)//输出文件信息
{
fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);
printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);
}
fclose(fp);
printf("\t\t\t\t按任意键返回\n");
getch();//返回
jieshuxitong();
}本回答被提问者采纳
相似回答