Visual Studio中stricmp和_stricmp的区别? [英] Difference of stricmp and _stricmp in Visual Studio?
问题描述
我可能会问一个愚蠢的问题,但我真的无法在Google上找到答案,而且我仍然是使用MSVS的初学者。
I may asking a stupid question, but I really can't find an answer with google plus I am still a beginner of using MSVS.
我最近需要使用函数比较两个字符串。我不明白stricmp和_stricmp的区别。它们都可以用于比较字符串并返回相同的结果。我去检查了它们:
I recently need to use functions to make comparison of two strings. What I don't understand is the difference of stricmp and _stricmp. They both can be used to compare strings and return the same results. I went to check them:
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 );
}
结果表明它们是相同的:
result shows they are the same:
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
我想知道为什么...
I am wondering why...
推荐答案
stricmp
是POSIX函数,而不是标准的C90函数。为避免名称冲突,Microsoft不建议使用不符合标准的名称( stricmp
),并建议使用 _stricmp
。功能上没有区别( stricmp
只是 _stricmp
的别名。)
stricmp
is a POSIX function, and not a standard C90 function. To avoid name clashes Microsoft deprecated the non-conforming name (stricmp
) and recommends using _stricmp
instead. There is no difference in functionality (stricmp
is merely an alias for _stricmp
.)
这篇关于Visual Studio中stricmp和_stricmp的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!