Compare characters in two buffers.
#include <memory.h> | Required only for function declarations | |
#include <string.h> | Use either STRING.H (for ANSI compatibility) or MEMORY.H |
int memcmp( const void *buf1, const void *buf2, size_t count );
int __far _fmemcmp( const void __far *buf1, const void __far *buf2,
size_t count );
buf1 | First buffer | |
buf2 | Second buffer | |
count | Number of characters |
The memcmp and _fmemcmp functions compare the first count bytes of buf1 and buf2 and return a value indicating their relationship, as follows:
Value | Meaning |
< 0 | buf1 less than buf2 |
= 0 | buf1 identical to buf2 |
> 0 | buf1 greater than buf2 |
The _fmemcmp function is a model-independent (large-model) form of the memcmp function. It can be called from any point in a program.
There is a semantic difference between the function version of memcmp and its intrinsic version. The function version supports huge pointers in compact-, large-, and huge-model programs, but the intrinsic version does not.
The memcmp and _fmemcmp functions return an integer value, as described above.
memcmp
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_fmemcmp
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
_memccpy, memchr, memcpy, memset, strcmp, strncmp
/* 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>
void main( void )
{
char first[] = "12345678901234567890";
char second[] = "12345678901234567891";
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 if( result > 0 )
printf( "First is greater than second.\n" );
printf( "Compare '%.20s' to '%.20s':\n", first, second );
result = memcmp( first, second, 20 );
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 '1234567890123456789' to '1234567890123456789':
First is equal to second.
Compare '12345678901234567890' to '12345678901234567891':
First is less than second.