wmemcmp
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <wchar.h> で定義
|
||
int wmemcmp( const wchar_t *lhs, const wchar_t *rhs, size_t count ); |
(C95以上) | |
lhs および rhs の指すワイド文字 (または互換性のある整数型) 配列の先頭 count 個のワイド文字を比較します。 比較は辞書的に行われます。
結果の符号は比較する配列内の最初の異なるワイド文字の組の値の差の符号です。
count がゼロの場合、この関数は何もしません。
引数
| lhs, rhs | - | 比較するワイド文字配列を指すポインタ |
| count | - | 調べるワイド文字数 |
戻り値
lhs 内の最初の異なるワイド文字の値が rhs 内の対応するワイド文字の値より小さい (辞書順で lhs が rhs より前に来る) 場合は負の値。
lhs と rhs の count 個のワイド文字がすべて等しい場合は 0。
lhs 内の最初の異なるワイド文字の値が rhs 内の対応するワイド文字の値より大きい (辞書順で rhs が lhs より前に来る) 場合は正の値。
ノート
この関数はロケール対応でなく、コピーする wchar_t オブジェクトの値を気にしません。 ヌルも無効な文字も比較します。
例
Run this code
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
void demo(const wchar_t* lhs, const wchar_t* rhs, size_t sz)
{
for(size_t n = 0; n < sz; ++n) putwchar(lhs[n]);
int rc = wmemcmp(lhs, rhs, sz);
if(rc == 0)
wprintf(L" compares equal to ");
else if(rc < 0)
wprintf(L" precedes ");
else if(rc > 0)
wprintf(L" follows ");
for(size_t n = 0; n < sz; ++n) putwchar(rhs[n]);
wprintf(L" in lexicographical order\n");
}
int main(void)
{
setlocale(LC_ALL, "en_US.utf8");
wchar_t a1[] = {L'α',L'β',L'γ'};
wchar_t a2[] = {L'α',L'β',L'δ'};
size_t sz = sizeof a1 / sizeof *a1;
demo(a1, a2, sz);
demo(a2, a1, sz);
demo(a1, a1, sz);
}
出力:
αβγ precedes αβδ in lexicographical order
αβδ follows αβγ in lexicographical order
αβγ compares equal to αβγ in lexicographical order