CARM User's Guide

Discontinued

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:

ValueDescription
< 0buf1 less than buf2
= 0buf1 equal to buf2
> 0buf1 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");
}