wmemcmp ()- 比较宽字符缓冲区

格式

#include <wchar.h>
int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);

语言级别

ANSI

线程安全

宽字符函数

有关更多信息,请参阅 宽字符

描述

wmemcmp() 函数将 s1 指向的对象的前 n 个宽字符与 s2指向的对象的前 n 个宽字符进行比较。 如果 n 具有值 0 ,那么 wmemcmp() 函数将返回 0。

返回值

wmemcmp() 函数根据两个字符串 s1s2之间的关系返回值:

表 1. wmemcmp() 的返回值
含义
小于 0 s1 小于 s2
0 s1s2 完全相同
大于 0 s1 大于 s2

示例

此示例使用 wmemcmp() 函数将宽字符字符串与 out 进行比较。
#include <wchar.h>
#include <stdio.h>
#include <locale.h>
 
main()
{
   int rc;
   wchar_t *in = L"12345678";
   wchar_t *out = L"12AAAAAB";
   setlocale(LC_ALL, "POSIX");
 
   printf("\nGREATER is the expected result");
   rc = wmemcmp(in, out, 3);
   if (rc == 0)
      printf("\nArrays are EQUAL %ls %ls \n", in, out);
   else
   {
   if (rc > 0)
      printf("\nArray %ls GREATER than %ls \n", in, out);
   else
      printf("\nArray %ls LESS than %ls \n", in, out);
   }
}
 
   /******************************************************
      The output should be:
 
      GREATER is the expected result
      Array 12345678 GREATER than 12AAAAAB
   ******************************************************/

相关信息