Partager via


memcmp, wmemcmp (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Compare characters in two buffers.

int memcmp(    const void*buf1,    const void*buf2,    size_tcount);inline int wmemcmp(   const wchar_t*buf1,const wchar_t*buf2,size_tcount);

Parameters

  • buf1
    First buffer.
  • buf2
    Second buffer.
  • count
    Number of characters.

Return Values

The return value indicates the relationship between the buffers.

Return Value Relationship of First count Bytes of buf1 and buf2
< 0 buf1 less than buf2
0 buf1 identical to buf2
> 0 buf1 greater than buf2

Remarks

The memcmp function compares the first count bytes of buf1 and buf2 and returns a value indicating their relationship.

Example

/* 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" );
}

Output

Compare '1234567890123456789' to '1234567890123456789':
First is equal to second.
Compare '12345678901234567890' to '12345678901234567891':
First is less than second.

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h and wchar_ship.h.
Link Library: coredll.dll.

See Also

_memccpy | memchr | memcpy | memset | strcmp, strncmp

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.