memcmp, wmemcmp
Compare characters in two buffers.
int memcmp( const void *buf1, const void *buf2, size_t count ); int wmemcmp( const wchar_t * buf1, const wchar_t * buf2, size_t count );
Parameters
- buf1
-
First buffer.
- buf2
-
Second buffer.
- count
-
Number of characters (bytes for memcmp, wide characters for wmemcmp).
| Routine | Required header | Compatibility |
|---|---|---|
| memcmp | <memory.h> or <string.h> | ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| wmemcmp | <wchar.h> | ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
// 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" );
}
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.