strcmp, strncmp, strcasecmp, strncasecmp, strcasecmp_l, strncasecmp_l - string comparison
#include <string.h> int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
#include <strings.h> int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, size_t n);
int strcasecmp_l(const char *s1, const char *s2, locale_t locale);
int strncasecmp_l(const char *s1, const char *s2, size_t n, locale_t locale);
These functions compare two strings (arrays of characters), and return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 respectively. The strcmp(), strcasecmp(), and strcasecmp_l() functions require the strings to be terminated by a '\0' character. The strncmp(), strncasecmp(), and strncasecmp_l() functions limit their comparisons to no more than n bytes, allowing comparions of either an initial subset of the strings or of non-terminated strings.
The strcmp() function compares two strings byte-by-byte, according to the ordering of the "C" locale's character set. The function returns an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 respectively. The sign of a non-zero return value is determined by the sign of the difference between the values of the first pair of bytes that differ in the strings being compared. The strncmp() function makes the same comparison but looks at a maximum of n bytes. Bytes following a null byte are not compared.
The strcasecmp() and strncasecmp() functions are case-insensitive versions of strcmp() and strncmp() respectively. They ignore differences in case when comparing lowercase and uppercase characters, using the current locale of the process to determine the case of the characters.
The strcasecmp_l() and strncasecmp_l() functions are versions of strcasecmp() and strncasecmp() respectively. They use the locale represented by locale, instead of the current locale of the process.
The behavior is undefined if the locale argument is the special locale object LC_GLOBAL_LOCALE or is not a valid locale object handle.
See attributes(7) for descriptions of the following attributes:
|
See standards(7) for descriptions of the following standards:
|
memcmp(3C), newlocale(3C), setlocale(3C), strcoll(3C), string(3C), strxfrm(3C), u8_strcmp(3C), wcscmp(3C), wcscoll(3C), attributes(7), standards(7)
For some locales, strxfrm(3C) should be applied to the strings before they are passed to the functions.
The strcasecmp_l() and strncasecmp_l() functions were added to Oracle Solaris in the Solaris 11.4.0 release.
The strcmp(), strcasecmp(), strncasecmp(), strncmp() functions have been included in all Sun and Oracle releases of Solaris.