Jump to: navigation, search

Description

The strcoll() function compares the string pointed to by s1 to the string pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.

Return value

The strcoll() function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 when both are interpreted as appropriate to the current locale.

Prototype

Declared in string.h

The C89/C99 prototype is:

int strcoll(const char *s1, const char *s2);

Implementation

In standard C, this can be implemented as:

/* This code uses C99 VLAs */
#include <string.h> /* strxfrm() strcmp() */
int strcoll(const char *s1, const char *s2)
{
    char t1[1 + strxfrm(0, s1, 0)];
    strxfrm(t1, s1, sizeof(t1));
    char t2[1 + strxfrm(0, s2, 0)];
    strxfrm(t2, s2, sizeof(t2));
    return strcmp(t1, t2);
}

Compilable unit, portable C99 in implementation namespace; public domain; past reviewers: none; current reviews: none

References

The C Standard, 7.21.4.3 (C99 numbering)

Personal tools