请输入您要查询的百科知识:

 

词条 wcscmp
释义

strcmp, wcscmp一样都是比较字符串的指针函数原型

int strcmp( const char *string1, const char *string2 );

int wcscmp( const wchar_t *string1, const wchar_t *string2 );

参数

string1, string2 为以零值结尾的字符串所有版本的c运行库都支持

返回值

< 0string1 小于string2

0string1 相当 string2

> 0string1 大于 string2
wcscmp 比较宽字符

例子

/* STRCMP.C */

#include <string.h>

#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazyfox";

char string2[] = "The QUICK brown dog jumps over the lazyfox";

void main( void )

{

char tmp[20];

int result;

/* Case sensitive */

printf( "Comparestrings:\\\t%s\\\t%s\\", 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\", 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\", tmp );

}

结果

Compare strings:

The quick brown dog jumpsover the lazy fox

The QUICK brown dog jumpsover the lazy fox

strcmp: String1 is greater than string 2

_stricmp: String 1 isequal to string 2

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/6 11:39:11