printf("请输入第%d本图书书名\n",b+1);
scanf("%s",lurua.bookName);
printf("请输入第%d本图书作者名\n",b+1);
scanf("%s",lurua.auther);
printf("请输入第%d本图书编号\n",b+1);
scanf("%s",lurua.bookNumber);
printf("请输入第%d本图书出版单位\n",b+1);
scanf("%s",lurua.publisher);
printf("请输入第%d本图书出版时间\n",b+1);
scanf("%d",&lurua.publitionTime);
printf("请输入第%d本图书价格\n",b+1);
scanf("%f",&lurua.price);
printf("请输入第%d本图书总数量\n",b+1);
scanf("%d",&lurua.allNumber);
printf("请输入第%d本图书可借出数量\n",b+1);
scanf("%d",&lurua.availableNumber);
fprintf(fp,"%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);
b=b+1;
fclose(fp);
voidliulan()
Bookslurua;
charfileName[31],*name=fileName;
FILE*fp;
printf("请输入图书库文件及路径\n");
scanf("%s",name);
fp=fopen(name,"r");
if(fp!
=NULL)
printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t可借出数量\n");
while(!
feof(fp))
fscanf(fp,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber);
printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);}
printf("错误,请重新选择\n");
fclose(fp);
voidchaxunz()
charfilename[31];
printf("请输入图书库文件名及路径(小于30个字符)\n");
scanf("%s",filename);
FILE*fp;
fp=fopen(filename,"r");
Booksbook1;
charch='y';
inta;
charduqu[21],wenjian[21];
/*查询次循环*/
while((ch=='y')||(ch=='Y'))
printf("*********************\n");
printf("#1_按书名***2_按作者#\n");
printf("*********************\n");
printf("请选择?
\n");
scanf("%d",&a);
printf("请输入关键词;\n");
scanf("%s",duqu);
printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t可借出数量\n");
switch(a)
case1:
while(!
feof(fp))
fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1.publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber);strcpy(wenjian,book1.bookName);
if((bijiao(duqu,wenjian))==1)
printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.bookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.availableNumber);
};break;
case2:
while(!
feof(fp))
fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1.publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber);strcpy(wenjian,book1.auther);
if((bijiao(duqu,wenjian))==1)
printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.bookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.availableNumber);
FILE*fpa;
charbookNumbera[16];
intm=0,n,i;
Bookslurua;
charfilename[31];
printf("请输入库文件名及路径:
\n");
scanf("%s",filename);
fpa=fopen(filename,"r");
if(fpa!
=NULL)
while(!
feof(fpa))/*确定书本数*/
fscanf(fpa,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber);m=m+1;
Booksxiushana[m];
rewind(fpa);
/*全部读取至内存*/
for(i=0;ifscanf(fpa,"%s%s%s%s%d%f%d%d\n",xiushana[i].bookName,xiushana[i].auther,xiushana[i].bookNumber,xiushana[i].publisher,&xiushana[i].publitionTime,&xiushana[i].price,&xiushana[i].allNumber,&xiushana[i].availableNumber);
/*具体操作*/
printf("*********************\n");
printf("#1_修改*******2_删除#\n");
printf("*********************\n");
printf("请选择?
\n");
scanf("%d",&i);
switch(i)
case1:
printf("请输入需修改图书书名\n");
scanf("%s",lurua.bookName);
printf("请输入需修改图书作者名\n");
scanf("%s",lurua.auther);
printf("请输入需修改图书编号\n");
scanf("%s",lurua.bookNumber);
printf("请输入需修改图书出版单位\n");
scanf("%s",lurua.publisher);
printf("请输入需修改图书出版时间\n");
scanf("%d",&lurua.publitionTime);
printf("请输入第%d本图书价格\n");
scanf("%f",&lurua.price);
printf("请输入需修改图书总数量\n");
scanf("%d",&lurua.allNumber);
printf("请输入需修改图书可借出数量\n");
scanf("%d",&lurua.availableNumber);
for(i=0;iif((strcmp(lurua.bookNumber,xiushana[i].bookNumber))==0)n=i;
strcpy(xiushana[n].bookName,lurua.bookName);
strcpy(xiushana[n].bookNumber,lurua.bookNumber);
strcpy(xiushana[n].auther,lurua.auther);
strcpy(xiushana[n].publisher,lurua.publisher);
xiushana[n].publitionTime=lurua.publitionTime;
xiushana[n].price=lurua.price;
xiushana[n].allNumber=lurua.allNumber;
xiushana[n].availableNumber=lurua.availableNumber;
printf("修改成功\n");
};break;
case2:
printf("请输入需删图书编号:
\n");
scanf("%s",bookNumbera);
for(i=0;iif(strcmp(bookNumbera,xiushana[i].bookNumber)==0)
for(i=n;istrcpy(xiushana[i].bookName,xiushana[i+1].bookName);
strcpy(xiushana[i].bookNumber,xiushana[i+1].bookNumber);strcpy(xiushana[i].auther,xiushana[i+1].auther);
strcpy(xiushana[i].publisher,xiushana[i+1].publisher);
xiushana[i].publitionTime=xiushana[i+1].publitionTime;
xiushana[i].price=xiushana[i+1].price;
xiushana[i].allNumber=xiushana[i+1].allNumber;
xiushana[i].availableNumber=xiushana[i+1].availableNumber;}
fclose(fpa);
fpa=fopen(filename,"w");
for(i=0;ifprintf(fpa,"%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",xiushana[i].bookName,xiushana[i].auther,xiushana[i].bookNumber,xiushana[i].publisher,xiushana[i].publitionTime,xiushana[i].price,xiushana[i].allNumber,xiushana[i].availableNumber);
printf("删除成功。
\n");
fclose(fpa);
break;
default:
;break;
printf("error\n");
#include
#include
#include
typedefstructBooks/*图书信息结构体*/
charbookName[21];
charauther[21];
charbookNumber[16];
charpublisher[21];
intpublitionTime;
floatprice;
intallNumber;
intavailableNumber;
}Books;
voidluru();/*录入函数*/
voidliulan();/*浏览函数*/
voidchaxunz();/*关键字搜索,如搜"线性代数"可用关键字"线代"*/
intbijiao(chara[],charb[]);/*关键字查询主要靠该函数*/
voidxiushan();/*修改删除函数*/
intmain()
printf("========图书信息管理系统=======\n");
inta;
charch='y';
/*执行主循环*/
while((ch=='y')||(ch=='Y'))
printf("===============================\n");
printf("*1_信息录入====*====2_信息浏览*\n");
printf("*==============*==============*\n");
printf("*3_信息查询====*====4_信息修删*\n");
printf("===============================\n");
printf("请选择需要的功能\n");
scanf("%d",&a);
switch(a)
case1:
luru();break;
case2:
liulan();break;
case3:
chaxunz();break;
case4:
xiushan();break;
default:
printf("输入错误\n");break;
printf("是否继续管理:
yorn\n");
scanf("%c",&ch);
scanf("%c",&ch);
voidluru()
Bookslurua;
intc,b=0;
charfileName[31],*name=fileName;
printf("请输入管理图书文件名及路径\n");
scanf("%s",name);
FILE*fp;
fp=fopen(name,"a");
if(fp==NULL)
printf("错误请重新选择\n");
printf("请输入入库数量\n");
scanf("%d",&c);
while(bprintf("请输入第%d本图书书名\n",b+1);
scanf("%s",lurua.bookName);
printf("请输入第%d本图书作者名\n",b+1);
scanf("%s",lurua.auther);
printf("请输入第%d本图书编号\n",b+1);
scanf("%s",lurua.bookNumber);
printf("请输入第%d本图书出版单位\n",b+1);
scanf("%s",lurua.publisher);
printf("请输入第%d本图书出版时间\n",b+1);
scanf("%d",&lurua.publitionTime);
printf("请输入第%d本图书价格\n",b+1);
scanf("%f",&lurua.price);
printf("请输入第%d本图书总数量\n",b+1);
scanf("%d",&lurua.allNumber);
printf("请输入第%d本图书可借出数量\n",b+1);
scanf("%d",&lurua.availableNumber);
fprintf(fp,"%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);
b=b+1;
fclose(fp);
voidliulan()
Bookslurua;
charfileName[31],*name=fileName;
FILE*fp;
printf("请输入图书库文件及路径\n");
scanf("%s",name);
fp=fopen(name,"r");
if(fp!
=NULL)
printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t可借出数量\n");
while(!
feof(fp))
fscanf(fp,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber);
printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);}
printf("错误,请重新选择\n");
fclose(fp);
voidchaxunz()
charfilename[31];
printf("请输入图书库文件名及路径(小于30个字符)\n");
scanf("%s",filename);
FILE*fp;
fp=fopen(filename,"r");
Booksbook1;
charch='y';
inta;
charduqu[21],wenjian[21];
/*查询次循环*/
while((ch=='y')||(ch=='Y'))
printf("*********************\n");
printf("#1_按书名***2_按作者#\n");
printf("*********************\n");
printf("请选择?
\n");
scanf("%d",&a);
printf("请输入关键词;\n");
scanf("%s",duqu);
printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t可借出数量\n");
switch(a)
case1:
while(!
feof(fp))
fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1.publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber);strcpy(wenjian,book1.bo