compare strings according to current collation

You're viewing an older version of this page (#3499). View the current version.

View versions (3)

NAME

<span class="Nm" id="strcoll">strcoll</span>, <span class="Nm" id="strcoll_l">strcoll_l</span>

INTERFACE

#include <string.h> int strcoll ( const char *s1, const char *s2 ) #include <xlocale.h> int strcoll_l ( const char *s1, const char *s2, locale_t loc )

DESCRIPTION

The strcoll function lexicographically compares the null-terminated strings &#92;c s1 and &#92;c s2 according to the current locale collation if any, otherwise call &#92;c strcmp, and returns an integer greater than, equal to, or less than 0, according as &#92;c s1 is greater than, equal to, or less than &#92;c s2.

While the strcoll function uses the current locale, the strcoll_l function may be passed a locale directly. See xlocale for more information.

Example 1

#include <stdio.h>
#include <string.h>

int main()
{
  // define two strings s, t and initialize s
  char s[10] = "testing", t[10];

  // copy s to t
  strcpy(t, s);

  // test if s is identical to t
  if (!strcoll(s, t))
    printf("The strings are identical.\n");
  else
    printf("The strings are different.\n");

  return 0;
}

Output:

The strings are identical.

SEE ALSO

strcmp, strxfrm

STANDARDS

The strcoll function conforms to ISO/IEC 9899:1990 ("ISO C90").