Keil Logo

memcmp

Summary
#include <string.h>

int memcmp (
  const void *buf1,    /* first buffer */
  const void *buf2,    /* second buffer */
  unsigned int len);   /* bytes to compare */
Description

The memcmp function compares the first len bytes from buf1 and buf2 and returns a value indicating their relationship as follows:

Value Description
< 0 buf1 less than buf2
= 0 buf1 equal to buf2
> 0 buf1 greater than buf2
Return Value

The memcmp function returns a positive, negative, or zero value indicating the relationship of buf1 and buf2.

See Also

memccpy, memchr, memcpy, memmove, memset

Example
#include <string.h>
#include <stdio.h> /* for printf */

void tst_memcmp (void) {
  char hexchars [] = "0123456789ABCDEF";
  char hexchars2 [] = "0123456789abcdef";
  char i;

  i = memcmp (hexchars, hexchars2, 16);

  if (i < 0)
    printf ("hexchars < hexchars2\n");
  else if (i > 0)
    printf ("hexchars > hexchars2\n");
  else
    printf ("hexchars == hexchars2\n");
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.