【发布时间】:2013-07-10 10:46:12
【问题描述】:
我有这个功能,但是我的 fgets 功能不能正常工作,谁能帮帮我? 在案例 3 中,我要求用户输入他想要搜索酒店的内容,例如部分单词、两个单词等。当我运行它时它无法正常工作,我不明白为什么。
scanf("%d", &option);
case 3:
printf("\nEnter the name of the hotel you want to search for.\n\n>>>");
fgets(asked_hotel, sizeof(asked_hotel)-1, stdin);
printf("The hotels matching what you searched are:\n\n");
find_hotel(hotel_name,hotel_rating,address_name,city_name,address_code,NUM_HOTELS,asked_hotel);
【问题讨论】:
-
你得到什么结果,你期望什么?
-
另外,
fgets函数很可能不是问题,而是find_hotel函数有问题。 -
@JoachimPileborg 当我选择案例 3(pres 3)时,它应该提示我输入我搜索的单词,但它会自行打印所有酒店。
-
那么现在是了解它的好时机。谷歌“gdb 教程”可以获得数百万个关于此的文档。热门歌曲,cs.cmu.edu/~gilpin/tutorial
-
@PHIfounder,呵呵,不知道