库函数strcmp的使用用法举例

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:16:41
C语言中strcmp的使用方法那位能给个详细点的例子
为什么在编译时会出现“expected primary-expression before ']'token”的编译器错误提示?就是对于a[]之类的数组而言的

以下摘自MSDN:

Example

/* STRCMP.C */

#include <string.h>
#include <stdio.h>

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 = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )