【发布时间】:2013-01-30 00:27:09
【问题描述】:
可能重复:
Why does strcmp() return 0 when its inputs are equal?
strcmp results in false when strings are equal
我真的不明白为什么函数检查返回真!!!我使用 strcmp 来比较 char[] 指针(hello)和字符数组“bar”。
bool check(const char* word);
char pointer[] = "hello";
int main (void)
{
bool answer = check(pointer) ;
if(answer == true)
printf("true");
else
printf("false");
return 0;
}
bool check(const char* word)
{
printf(" word = %s ", word);
if(strcmp( word , "bar"))
return true;
else
return false;
}
【问题讨论】:
-
strcmp在字符串不同时返回非零值。 -
阅读精美手册。具体来说,对于
strcmp。 -
正好相反!!。