佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1259|回复: 3

求救!user input error

[复制链接]
发表于 19-8-2011 05:57 PM | 显示全部楼层 |阅读模式
本帖最后由 无知小子92 于 19-8-2011 06:23 PM 编辑

我的 assignment 是做关于 library system 的

在让 学生 search book 的那一 part
我遇到了问题!

我的问题是,
如果学生 key in 的 call number 没有出现在我的 file,就 show error message
然后 loop 回去再让 学生 key in 一次~
是可以 loop 回去, 但是 loop 回去后,再次得到 search_call_no,接下去的process 就走不到了~

请各位善心人士救救小弟!
感激不尽!



  1.                     do
  2.                     {
  3.                         sum=0;
  4.                         i=0;

  5.                         fflush(stdin);
  6.                         printf("Please enter call number: ");
  7.                         scanf("%s", search_call_no);

  8.                         while((fscanf(book, "%s\t%s\t%s\t%s\t%s\t%s\t%s", call_no, author, pub_date, title, pub_loc, pub_name, isbn)) != EOF)
  9.                         {
  10.                            
  11.                             a = check[i] = (strcmp(search_call_no, call_no));
  12.                             i++;
  13.                             sum = sum + a;

  14.                             if((strcmp(search_call_no, call_no)) == 0)
  15.                             {
  16.                                 printf("\nCall Number\t: %s\n", call_no);
  17.                                 printf("Author\t\t: %s\n", author);
  18.                                 printf("Public Date\t: %s\n", pub_date);
  19.                                 printf("Title\t\t: %s\n", title);
  20.                                 printf("Public Location\t: %s\n", pub_loc);
  21.                                 printf("Public Name\t: %s\n", pub_name);
  22.                                 printf("ISBN\t\t: %s\n\n", isbn);
  23.                             }

  24.                         }

  25.                         //printf("%d", sum);

  26.                         if(sum <= -10 || sum >= 10)
  27.                         {
  28.                             printf("WRONG!!!\n\n");
  29.                         }

  30.                     }while(sum <= -10 || sum >= 10);

复制代码
回复

使用道具 举报


ADVERTISEMENT

发表于 19-8-2011 07:24 PM | 显示全部楼层
本帖最后由 loonloon0625 于 19-8-2011 07:28 PM 编辑

接下去的process 就走不到了?
是不是没close file
回复

使用道具 举报

发表于 19-8-2011 07:50 PM | 显示全部楼层
本帖最后由 陈星星 于 19-8-2011 07:52 PM 编辑
我的 assignment 是做关于 library system 的

在让 学生 search book 的那一 part
我遇到了问题!

我 ...
无知小子92 发表于 19-8-2011 05:57 PM


可能你的initial value 一直maintain着或者是logic error, 有warning messages吗?。。。请呈上你的output snapshot。。。
回复

使用道具 举报

发表于 20-8-2011 10:42 AM | 显示全部楼层
你的fscanf()已经把File Pointer移动到eof的位置,你loop回去后没有fseek()到档案的开始位置,而是维持在档案的结尾。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 17-11-2025 05:19 AM , Processed in 0.099869 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表