int strcmp ( String1, String2)
const char *String1, *String2;
int strncmp (String1, String2,
Number)
const char *String1, *String2;
size_t Number;
int strcoll (String1, String2)
const char *String1, *String2;
int strcasecmp (String1, String2)
const char *String1, *String2;
int strncasecmp (String1, String2, Number)
const char *String1, *String2;
size_t Number;
The strcmp, strncmp, strcasecmp, strncasecmp, and strcoll subroutines compare strings in memory.
The String1 and String2 parameters point to strings. A string is an array of characters terminated by a null character.
The strcmp subroutine performs a case-sensitive comparison of the string pointed to by the String1 parameter and the string pointed to by the String2 parameter, and analyzes the extended ASCII character set values of the characters in each string. The strcmp subroutine compares unsigned char data types. The strcmp subroutine then returns a value that is:
The strncmp subroutine makes the same comparison as the strcmp subroutine, but compares up to the maximum number of pairs of bytes specified by the Number parameter.
The strcasecmp subroutine performs a character-by-character comparison similar to the strcmp subroutine. However, the strcasecmp subroutine is not case-sensitive. Uppercase and lowercase letters are mapped to the same character set value. The sum of the mapped character set values of each string is used to return a value that is:
The strncasecmp subroutine makes the same comparison as the strcasecmp subroutine, but compares up to the maximum number of pairs of bytes specified by the Number parameter.
Note: Both the strcasecmp and strncasecmp subroutines only work with 7-bit ASCII characters.
The strcoll subroutine works the same as the strcmp subroutine, except that the comparison is based on a collating sequence determined by the LC_COLLATE category. If the strcmp subroutine is used on transformed strings, it returns the same result as the strcoll subroutine for the corresponding untransformed strings.
Number | The number of bytes in a string to be examined. |
String1 | Points to a string which is compared. |
String2 | Points to a string which serves as the source for comparison. |
The strcmp,
strncmp, strcasecmp, strncasecmp, and
strcoll subroutines fail if the following occurs:
EFAULT | A string parameter is an invalid address. |
In addition, the
strcoll subroutine fails if:
EINVAL | A string parameter contains characters outside the domain of the collating sequence. |
These subroutines are part of Base Operating System (BOS) Runtime.
The memccpy, memchr, memcmp, memcpy, or memmove subroutine, setlocale (setlocale Subroutine) subroutine, strcat, strncat, strxfrm, strcpy, strncpy, or strdup (strcat, strncat, strxfrm, strcpy, strncpy, or strdup Subroutine) subroutine, strlen, strchr, strrchr, strpbrk, strspn, strcspn, strstr, or strtok (strlen, strchr, strrchr, strpbrk, strspn, strcspn, strstr, or strtok Subroutine) subroutine, swab (swab Subroutine) subroutine.
List of String Manipulation Subroutines, National Language Support, Multibyte and Wide Character String Collation Subroutines, Multibyte and Wide Character String Comparison Subroutines, Subroutines, Example Programs, and Libraries in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.