我想编写一个程序,比较用户输入的子字符串和字符串数组。strstr()函数
#include <stdio.h>
#include <string.h>
char animals[][20] = {
"dogs are cool",
"frogs are freaky",
"monkeys are crazy"
};
int main() {
char input[10];
puts("Enter animal name: ");
fgets(input, sizeof(input), stdin);
int i;
for(i = 0; i < 3; i++) {
if(strstr(animals[i], input))
printf("%s", animals[i]);
}
return 0;
}
当我进入青蛙,例如它应该打印消息“青蛙怪异”,但它没有打印任何东西。
所以我试着写一行来打印出strstr()函数的值,每次都返回0,这意味着所有的比较都失败了。我不明白为什么,有人可以帮我吗?
'* p = 0时;''== * P =“\ 0'' ?? –
@mf_ yeah [15个字符] – 2013-06-03 21:05:50