Keil Logo Arm Logo

CARM User's Guide

Discontinued

strncmp

Summary
#include <string.h>

int strncmp (
  const unsigned char *string1,  /* first string */
  const unsigned char *string2,  /* second string */
  unsigned int len);             /* max characters to compare */
Description

The strncmp function compares the first len bytes of string1 and string2 and returns a value indicating their relationship.

Return Value

The strncmp function returns the following values to indicate the relationship of the first len bytes 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, strcmp

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

void tst_strncmp (void) {
  unsigned char str1 [] = "Wrodanahan T.J.";
  unsigned char str2 [] = "Wrodanaugh J.W.";
  char i;

  i = strncmp (str1, str2, 15);

  if (i < 0)
    printf ("str1 < str2\n");
  else if (i > 0)
    printf ("str1 > str2\n");
  else
    printf ("str1 == str2\n");
}

Keil logo

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.