This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
strcoll
Prototype
#include <string.h>
int strcoll(const char *s1, const char *s2);
Description
Compares the two strings s1
and s2
character by character
up to the terminating null character. It returns an integer
less than, equal to, or greater than zero if s1
is found,
respectively, to be less than, to match, or be greater than s2
.
The comparison is based on the current locale settings (set
by the setlocale
function).
Example
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* collstr.c: compare the two argument strings.
* usage: collstr <string1> <string2>
*/
int main(int argc, char **argv)
{
int i;
if (argc != 3) {
fprintf(stderr, "usage: %s <string1> <string2>\n",
argv[0]);
return EXIT_FAILURE;
}
setlocale(LC_ALL, "");
i = strcoll(argv[1], argv[2]);
printf("`%s' is %s `%s'\n", argv[1],
((i > 0) ? "greater than" :
(i < 0) ? "less than" : "equal to"), argv[2]);
return EXIT_SUCCESS;
}
References
ISO C 9899:1990 7.11.4.3