In C, stricmp() compares two C-strings and ignores letter case. On modern Microsoft compilers the preferred name is _stricmp(). It is not portable ISO C.
You pass two C-strings. Both are required. The result uses the same 0 / less than 0 / greater than 0 idea as strcmp(). Include the header your compiler documents for this function.
Syntax
Pass both strings. Start with this call.
C
stricmp("Hello", "hello");
Call
What it does
stricmp("Hello", "hello")
Returns 0 because the letters match when case is ignored.
On Windows prefer _stricmp. On POSIX, use strcasecmp().
Library declarations
C
int stricmp(const char *s1, const char *s2);
int _stricmp(const char *s1, const char *s2);
Parameters
Parameter
Description
s1
Required. The first C-string.
s2
Required. The second C-string.
Return Value
Return Value
Description
0
The strings match when letter case is ignored.
Less than 0
The first string comes first.
Greater than 0
The first string comes after.
C Examples
Example 1 — Equal Ignoring Case
"Hello" and "hello" compare as equal with stricmp.
C
#include <stdio.h>
#include <string.h>
int main(void) {
int r = stricmp("Hello", "hello");
if (r == 0) {
printf("equal (ignore case)\n");
} else {
printf("not equal\n");
}
return 0;
}
Output
equal (ignore case)
How It Works
Compare both strings. Letters are matched after folding case.
Return is zero. Every character pair matches when case is ignored.
Branch on == 0. That is the usual “are these the same?” test.
Contrast with strcmp.strcmp would report them as different.
Example 2 — Case-Insensitive Command Match
Accept user input like "Quit", "QUIT", or "quit" as the same command.