示例
第一个 if 语句用来检查自变量是否相同,但是只有在不同的时候,该语句才会成功执行。

void foo( char *string1, char *string2)
{
if( strcmp(string1, string2) ) {
//the strings are the different
}

if( !strcmp(string1, string2) ) {
//the strings are the same
}
}

解决方案
为避免误解,编码准则可能需要 if 语句按如下方式编写。

void foo( char *string1, char *string2)
{
if(strcmp(string1, string2) != 0) {
//the strings are the different
}

if( strcmp(string1, string2) == 0) {
//the strings are the same
}
}