Share via


_memicmp, _memicmp_l

比較兩個緩衝區中的字元 (不區分大小寫)。

語法

int _memicmp(
   const void *buffer1,
   const void *buffer2,
   size_t count
);
int _memicmp_l(
   const void *buffer1,
   const void *buffer2,
   size_t count,
   _locale_t locale
);

參數

buffer1
第一個緩衝區。

buffer2
第二個緩衝區。

count
字元數。

locale
要使用的地區設定。

傳回值

傳回值表示緩衝區之間的關聯性。

傳回值 buf1 和 buf2 的前幾個位元組的關聯性
< 0 buffer1 小於 buffer2
0 buffer1 等於 buffer2
> 0 buffer1 大於 buffer2
_NLSCMPERROR 發生錯誤。

備註

_memicmp 函式會逐位元組比較兩個緩衝區 buffer1buffer2 的前 count 個位元組。 比較不區分大小寫。

buffer1如果 或 buffer2 為 Null 指標,此函式會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續執行,函式會傳回 _NLSCMPERROR,並將 errno 設為 EINVAL

_memicmp 會針對與地區設定相關的行為使用目前的地區設定;_memicmp_l 與其相同,只不過它會改用傳入的地區設定。 如需詳細資訊,請參閱 Locale

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
_memicmp <memory.h > 或 < string.h>
_memicmp_l <memory.h > 或 < string.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_memicmp.c
// This program uses _memicmp to compare
// the first 29 letters of the strings named first and
// second without regard to the case of the letters.

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

int main( void )
{
   int result;
   char first[] = "Those Who Will Not Learn from History";
   char second[] = "THOSE WHO WILL NOT LEARN FROM their mistakes";
   // Note that the 29th character is right here ^

   printf( "Compare '%.29s' to '%.29s'\n", first, second );
   result = _memicmp( first, second, 29 );
   if( result < 0 )
      printf( "First is less than second.\n" );
   else if( result == 0 )
      printf( "First is equal to second.\n" );
   else if( result > 0 )
      printf( "First is greater than second.\n" );
}
Compare 'Those Who Will Not Learn from' to 'THOSE WHO WILL NOT LEARN FROM'
First is equal to second.

另請參閱

緩衝區操作
_memccpy
memchr, wmemchr
memcmp, wmemcmp
memcpy, wmemcpy
memset, wmemset
_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l
_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l