stricmp() — Compare Strings without Case Sensitivity
Format
#include <string.h>
int stricmp(const char *string1, const char *string2);
Note: The
stricmp()
function is available
for C++ programs. It is available for C only when the program defines
the __cplusplus__strings__ macro.Language Level
Extension
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
The stricmp()
function compares string1 and string2 without
sensitivity to case. All alphabetic characters in the two arguments string1 and string2 are
converted to lowercase before the comparison.
The function operates on null-ended strings. The string arguments to the function are expected to contain a null character (\0) marking the end of the string.
Return Value
The stricmp()
function returns
a value indicating the relationship between the two strings, as follows:
Value | Meaning |
---|---|
Less than 0 | string1 less than string2 |
0 | string1 equivalent to string2 |
Greater than 0 | string1 greater than string2 |
Example
This example uses
stricmp()
to
compare two strings. #include <stdio.h>
#include <string.h>
int main(void)
{
/* Compare two strings as lowercase */
if (0 == stricmp("hello", "HELLO"))
printf("The strings are equivalent.\n");
else
printf("The strings are not equivalent.\n");
return 0;
}
The output should be: The strings are equivalent.
Related Information
- strcmpi() — Compare Strings Without Case Sensitivity
- strcoll() — Compare Strings
- strcspn() — Find Offset of First Character Match
- strdup() — Duplicate String
- strncmp() — Compare Strings
- strcasecmp() — Compare Strings without Case Sensitivity
- strncasecmp() — Compare Strings without Case Sensitivity
- strnicmp() — Compare Substrings Without Case Sensitivity
- wcscmp() — Compare Wide-Character Strings
- wcsncmp() — Compare Wide-Character Strings
- <string.h>