所以,我想做的是让用户搜索奶酪并将其显示在屏幕上。我对后者有问题。我似乎无法显示字符串,但我的代码仍在运行。这是我的代码:
#include<stdio.h>
#include<string.h>
char cheeses[][20] = {
"Cheddar",
"White Cheddar",
"Colby Jack",
"Gouda",
"Blue Cheese",
"Gorgonzola",
"Asiago",
"Limburger",
"Feta",
"Brie",
"Goat",
};
void find_cheese(const 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;
}
那么在这种情况下我该怎么办。我想要它,以便您可以输入“Lim”并让它显示 Limburger(将来它将能够显示有关奶酪的信息)。我将如何做到这一点?