我正在尝试列出一份奶酪列表,您可以通过搜索找到某个奶酪。完成后,我还想添加有关每个人的信息。但是每次我运行我的代码时,我都会得到标题中显示的错误。这是我的代码:
#include<stdio.h>
#include<string.h>
int main()
{
char cheeses[][20] = {
"Cheddar",
"White Cheddar",
"Colby Jack",
"Gouda",
"Blue Cheese",
"Gorgonzola",
"Asiago",
"Limburger",
"Feta",
"Brie",
};
void find_cheese(char search_for)
{
int i;
for (i = 0; i < 5; i++) {
if (strstr(cheeses[i], search_for))
printf("Cheese %i: '%s'\n", i, cheeses[i]);
}
}
int main()
{
char search_for[20];
printf("Search for: ");
fgets(search_for, 20, stdin);
find_cheese(search_for);
return 0;
}
}
为什么会这样?我在我的书里查过,但似乎找不到答案。