[c]代码库
void searchbook()//查询函数
{
FILE *fp;
int choose;
int ttid=0,tid=0,tamount=0,n=0,k=0,i,l;
char tname[20]= {'\0'},ttauthor[20]= {'\0'},tauthor[20]= {'\0'},ttpublishing[20]= {'\0'},tpublishing[20]= {'\0'}, deletebookname[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();
booksystem();
}
l=stockcount();//获得库存文件中图书个数
choose=searchmenu();
fflush(stdin);
while (1)
{
switch(choose)//功能函数选择
{
case 1:
system ("cls");
printf("\n");
printf("请输入编号:");
scanf("%d",&ttid);
break;
case 2:
system ("cls");
printf("\n");
printf("请输入书名:");
scanf("%s",deletebookname);
break;
case 3:
system ("cls");
printf("\n");
printf("请输入作者:");
scanf("%s",ttauthor);
break;
case 4:
system ("cls");
printf("\n");
printf("请输入出版社:");
scanf("%s",ttpublishing);
break;
case 5:
booksystem();
break;
default:
printf("您的输入有误,请重新输入。\n");
getch();
booksystem();
break;
}
break;
}
system ("cls");
for (i=0; i<l; i++)
{
fscanf(fp,"%d%s%s%s%d",&tid,tname,tauthor,tpublishing,&tamount);//读文件信息
if (ttid==tid||!strcmp(deletebookname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttpublishing,tpublishing))//输出查询信息
{
if (k==0)
{
printf("\n查询结果:\n\n");
printf("编号\t书名\t\t作者\t\t出版社\t\t\t库存量 \n");
}
printf("%-7d %-15s %-15s %-23s %-5d \n",tid,tname,tauthor,tpublishing,tamount);
k++;
}
}
if (k==0)//文件夹为空则输出无记录
{
system ("cls");
printf("\n\n\n\n\t\t\t\t无符合的记录。\n");
getch();
booksystem();
}
fclose(fp);
getch();
booksystem();
}
[源代码打包下载]
初级程序员
by: 云代码会员 发表于:2016-09-24 11:15:33 顶(0) | 踩(0) 回复
不错
回复评论