Previous Page
Next Page

memcmp

Compares two memory blocks

#include <string.h>
int memcmp (const void *b1 , const void *b2 , size_t n  );

The memcmp( ) function compares the contents two memory blocks of n bytes, beginning at the addresses in b1 and b2, until it finds a byte that doesn't match. The function returns a value greater than zero if the first mismatched byte (evaluated as unsigned char) is greater in b1, or less than zero if the first mismatched byte is greater in b2, or zero if the two buffers are identical over n bytes.

Example

long setone[5] = { 1, 3, 5, 7, 9 };
long settwo[5] = { 0, 2, 4, 6, 8 };

for ( int i = 0; i < 5; i++ )
  settwo[i] += 1;

if ( memcmp( &setone, &settwo, sizeof(settwo) ) == 0 )
  printf( "The two arrays are identical, byte for byte.\n" );

See Also

strcmp( ), strncmp( ), wmemcmp( )


Previous Page
Next Page