[C] 图书馆 →→→→→进入此内容的聊天室

来自 , 2020-06-01, 写在 C, 查看 100 次.
URL http://www.code666.cn/view/82089746
  1. void searchbook()//查询函数
  2. {
  3.     FILE *fp;
  4.     int choose;
  5.     int ttid=0,tid=0,tamount=0,n=0,k=0,i,l;
  6.     char tname[20]= {'\0'},ttauthor[20]= {'\0'},tauthor[20]= {'\0'},ttpublishing[20]= {'\0'},tpublishing[20]= {'\0'}, deletebookname[20]= {'\0'};
  7.     if ((fp=fopen("library.txt","r"))==NULL)//打开文件
  8.     {
  9.         system ("cls");
  10.         printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在,请按任意键返回。");
  11.         getch();
  12.         booksystem();
  13.     }
  14.   l=stockcount();//获得库存文件中图书个数    
  15.   choose=searchmenu();
  16.     fflush(stdin);
  17.     while (1)
  18.     {
  19.         switch(choose)//功能函数选择
  20.         {
  21.         case 1:
  22.             system ("cls");
  23.             printf("\n");
  24.             printf("请输入编号:");
  25.             scanf("%d",&ttid);
  26.             break;
  27.         case 2:
  28.             system ("cls");
  29.             printf("\n");
  30.             printf("请输入书名:");
  31.             scanf("%s",deletebookname);
  32.             break;
  33.         case 3:
  34.             system ("cls");
  35.             printf("\n");
  36.             printf("请输入作者:");
  37.             scanf("%s",ttauthor);
  38.             break;
  39.         case 4:
  40.             system ("cls");
  41.             printf("\n");
  42.             printf("请输入出版社:");
  43.             scanf("%s",ttpublishing);
  44.             break;
  45.         case 5:
  46.             booksystem();
  47.             break;
  48.         default:
  49.             printf("您的输入有误,请重新输入。\n");
  50.             getch();
  51.             booksystem();
  52.             break;
  53.         }
  54.         break;
  55.     }
  56.    
  57.     system ("cls");
  58.     for (i=0; i<l; i++)
  59.     {
  60.         fscanf(fp,"%d%s%s%s%d",&tid,tname,tauthor,tpublishing,&tamount);//读文件信息
  61.         if (ttid==tid||!strcmp(deletebookname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttpublishing,tpublishing))//输出查询信息
  62.         {
  63.             if (k==0)
  64.             {
  65.                 printf("\n查询结果:\n\n");
  66.                 printf("编号\t书名\t\t作者\t\t出版社\t\t\t库存量 \n");
  67.             }
  68.             printf("%-7d %-15s %-15s %-23s %-5d \n",tid,tname,tauthor,tpublishing,tamount);
  69.             k++;
  70.         }
  71.     }
  72.     if (k==0)//文件夹为空则输出无记录
  73.     {
  74.         system ("cls");
  75.         printf("\n\n\n\n\t\t\t\t无符合的记录。\n");
  76.         getch();
  77.         booksystem();
  78.     }
  79.     fclose(fp);
  80.     getch();
  81.     booksystem();
  82. }
  83.  
  84.  

回复 "图书馆"

这儿你可以回复上面这条便签

captcha