wcscmp

strcmp, wcscmp一樣都是比較字元串的指針函式原型

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

基本介紹

  • 中文名:wcscmp
  • 釋義指針函式原型
  • 性質:專業術語
  • 來源:數學算法
參數,函式代碼,輸出結果,

參數

int wcscmp( const wchar_t *string1, const wchar_t *string2 );
string1, string2 為以零值結尾的字元串所有版本的c運行庫都支持
返回值
< 0
string1 小於string2
0
string1string2相等
> 0
string1 大於 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:\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 );
}

輸出結果

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

相關詞條

熱門詞條

聯絡我們