3.2.34. strcmp

Compares two strings.

Syntax

unsigned long strcmp (str1, str2)
char *str1;
char *str2;

where:

str1

Variable of type pointer to char. Specifies the location in memory of the first byte of a character string.

str2

Variable of type pointer to char. Specifies the location in memory of the first byte of a character string.

Description

This macro compares two strings based on the internal machine representation of the characters.

For example, ASCII A has the value 41 in hexadecimal notation and ASCII B has the value 42 in hexadecimal notation. Therefore, A is less than B.

This macro behaves like the strcmp function in the ANSI C string library.

Return value

int

One of the following:

<0

Indicates that the second argument string value comes after the first argument string value in the machine collating sequences, str1 < str2.

0

Indicates that the two strings are identical in content.

>0

Indicates that the first argument string value comes after the second argument string value in the machine collating sequences, str2 < str1.

Rules

  • Strings are assumed to be NUL terminated or to fit within the array boundaries.

  • Comparisons are always signed, regardless of how the string is declared.

Example

This example shows how to use strcmp on the command line:

> ce strcmp("string1","string2")
  Result is: 4294967295  0xFFFFFFFF

See Also

Copyright © 2002-2009 ARM Limited. All rights reserved.ARM DUI 0175K
Non-Confidential