Keil Logo


#include <string.h>

int strcmp (
  const unsigned char *string1,    /* first string */
  const unsigned char *string2);   /* second string */

The strcmp function compares the contents of string1 and string2 and returns a value indicating their relationship.

Return Value

The strcmp function returns the following values to indicate the relationship of string1 to string2:

Value Description
< 0 string1 is less than string2
= 0 string1 is equal to string2
> 0 string1 is greater than string2
See Also

memcmp, strncmp

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

void tst_strcmp (void) {

  unsigned char buf1 [] = "Bill Smith";
  unsigned char buf2 [] = "Bill Smithy";
  int i;

  i = strcmp (buf1, buf2);

  if (i < 0)
    printf ("buf1 < buf2\n");
  else if (i > 0)
    printf ("buf1 > buf2\n");
    printf ("buf1 == buf2\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.