We recommend using Visual Studio 2017

_memicmp, _memicmp_l


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _memicmp, _memicmp_l.

Compares characters in two buffers (case-insensitive).

int _memicmp(  
   const void *buf1,  
   const void *buf2,  
   size_t count   
int _memicmp_l(  
   const void *buf1,  
   const void *buf2,  
   size_t count,  
   _locale_t locale  


First buffer.

Second buffer.

Number of characters.

Locale to use.

The return value indicates the relationship between the buffers.

Return valueRelationship of first count bytes of buf1 and buf2
< 0buf1 less than buf2.
0buf1 identical to buf2.
> 0buf1 greater than buf2.
_NLSCMPERRORAn error occurred.

The _memicmp function compares the first count characters of the two buffers buf1 and buf2 byte by byte. The comparison is not case-sensitive.

If either buf1 or buf2 is a null pointer, this function invokes an invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, the function returns _NLSCMPERROR and sets errno to EINVAL.

_memicmp uses the current locale for locale-dependent behavior; _memicmp_l is identical except that it uses the locale passed in instead. For more information, see Locale.

RoutineRequired header
_memicmp<memory.h> or <string.h>
_memicmp_l<memory.h> or <string.h>

For more compatibility information, see Compatibility in the Introduction.

// 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.  

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Buffer Manipulation
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