[Previous]
[Contents]
[Next]

memcmp(), _fmemcmp()

compare a given number of characters in two objects

Synopsis:

#include <string.h>
int memcmp( const void *s1,
            const void *s2,
            size_t length );
int _fmemcmp( const void __far *s1,
              const void __far *s2,
              size_t length );

Description:

The memcmp() function compares the first length characters of the object pointed to by s1 to the object pointed to by s2.

The _fmemcmp() function is a data-model-independent form of the memcmp() function that accepts far pointer arguments. It is most useful in mixed memory model applications.

Returns:

An integer, with the value given below:

Less than 0
the object pointed to by s1 is less than the object pointed to by s2.
0
the object pointed to by s1 is equal to the object pointed to by s2.
Greater than zero
the object pointed to by s1 is greater than the object pointed to by s2.

Examples:

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

void main()
  {
    char buffer[80];

    strcpy( buffer, "World" );
    if( memcmp( buffer, "hello", 5 ) < 0 ) {
      printf( "Less than\n" );
    } else {
      printf( "Equal to or greater than\n");
    }
  }

produces the output:

Less than

Classification:

memcmp() is ANSI; _fmemcmp() is WATCOM.
Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

memchr(), memcpy(), memicmp(), memset()


[Previous]
[Contents]
[Next]