库函数strcmp的使用用法举例

C语言中strcmp的使用方法那位能给个详细点的例子为什么在编译时会出现“expectedprimary-expressionbefore']'token”的编译器错误提... C语言中strcmp的使用方法那位能给个详细点的例子
为什么在编译时会出现“expected primary-expression before ']'token”的编译器错误提示?就是对于a[]之类的数组而言的
展开
 我来答
feldspar
2007-12-11 · TA获得超过384个赞
知道小有建树答主
回答量:564
采纳率:0%
帮助的人:0
展开全部
以下摘自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 )
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 );
}

Output

Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox

strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式