次の方法で共有


memcmp、wmemcmp

2 桁の文字を比較します。

int memcmp(
   const void *buf1,
   const void *buf2,
   size_t count
);
int wmemcmp(
   const wchar_t * buf1,
   const wchar_t * buf2,
   size_t count
);

パラメーター

  • buf1
    最初のバッファー。

  • buf2
    番目にバッファー。

  • count
    文字 (memcmp のバイト wmemcmp のワイド文字の数)。

戻り値

戻り値はバッファーの関係を示します。

戻り値

buf1 と buf2 最初のバイト数の関係

< 0

buf1buf2 より小さい

0

buf2 と同様に buf1

> 0

buf2 より大きい buf1

解説

buf1 と buf2 の count の最初の文字を比較し関係を示す値を返します。

必要条件

ルーチン

必須ヘッダー

memcmp

<memory.h> または <string.h>

wmemcmp

<wchar.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

ライブラリ

C ランタイム ライブラリのすべてのバージョン。

使用例

// crt_memcmp.c
/* This program uses memcmp to compare
 * the strings named first and second. If the first
 * 19 bytes of the strings are equal, the program
 * considers the strings to be equal.
 */

#include <string.h>
#include <stdio.h>

int main( void )
{
   char first[]  = "12345678901234567890";
   char second[] = "12345678901234567891";
   int int_arr1[] = {1,2,3,4};
   int int_arr2[] = {1,2,3,4};
   int result;

   printf( "Compare '%.19s' to '%.19s':\n", first, second );
   result = memcmp( first, second, 19 );
   if( result < 0 )
      printf( "First is less than second.\n" );
   else if( result == 0 )
      printf( "First is equal to second.\n" );
   else
      printf( "First is greater than second.\n" );

   printf( "Compare '%d,%d' to '%d,%d':\n", int_arr1[0], int_arr1[1], int_arr2[0], int_arr2[1]);
   result = memcmp( int_arr1, int_arr2, sizeof(int) * 2 );
   if( result < 0 )
      printf( "int_arr1 is less than int_arr2.\n" );
   else if( result == 0 )
      printf( "int_arr1 is equal to int_arr2.\n" );
   else 
      printf( "int_arr1 is greater than int_arr2.\n" );
}

出力

Compare '1234567890123456789' to '1234567890123456789':
First is equal to second.
Compare '1,2' to '1,2':
int_arr1 is equal to int_arr2.

同等の .NET Framework 関数

該当なし標準 C 関数を呼び出すには、PInvoke を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。

参照

関連項目

バッファー操作

_memccpy

memchr、wmemchr

memcpy、wmemcpy

memset、wmemset

strcmp、wcscmp、_mbscmp

strncmp、wcsncmp、_mbsncmp、_mbsncmp_l