我可能会问一个愚蠢的问题,但我真的无法通过谷歌找到答案,而且我仍然是使用 MSVS 的初学者。
我最近需要使用函数来比较两个字符串。我不明白的是stricmp和_stricmp的区别。它们都可用于比较字符串并返回相同的结果。我去检查他们:
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstricmp: String 1 is %s string 2\n", tmp );
/* Case insensitive */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
结果表明它们是相同的:
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
stricmp: String 1 is equal to string 2
_stricmp: String 1 is equal to string 2
我想知道为什么...