The stricmp() function compares two C-strings without regard to letter case. It is the Microsoft/Windows-style companion to POSIX strcasecmp()—ideal for matching user commands like quit and QUIT.
01
Ignore Case
A equals a.
02
Like strcmp
0 / sign.
03
Windows
string.h
04
_stricmp
MSVC name.
05
Extension
Not ISO C.
06
vs strcasecmp
POSIX twin.
Fundamentals
Definition and Usage
stricmp performs a case-insensitive lexicographic comparison of two strings. It walks both strings in parallel, folding ASCII letters before comparing bytes, and stops at the first difference or at the shared null terminator.
The function is not part of standard C. Microsoft documents _stricmp; many Windows programs still say stricmp. On Linux and macOS, use strcasecmp from <strings.h> instead.
💡
Beginner Tip
Test equality with stricmp(a, b) == 0. For cross-platform code, hide the platform name behind a macro or small wrapper that calls strcasecmp on POSIX and _stricmp on Windows.
Foundation
📝 Syntax
Typical Microsoft-style declaration:
C
int stricmp(const char *s1, const char *s2);
/* MSVC documented form: */
int _stricmp(const char *s1, const char *s2);
Headers and Portability
Windows (MSVC, MinGW) — #include <string.h>
Linux / macOS — use strcasecmp() in <strings.h>
Related — _strnicmp / bounded compare (Windows)
Return Value
0 — strings equal ignoring case.
< 0 — s1 less than s2 (case-insensitive order).
> 0 — s1 greater than s2.
Cheat Sheet
⚡ Quick Reference
s1
s2
stricmp result
"Hello, World!"
"hello, world!"
0 (equal)
"Yes"
"no"
> 0
"apple"
"Banana"
< 0
Windows
POSIX equivalent
stricmp / _stricmp ↔ strcasecmp
equality test
any pair
stricmp(a, b) == 0
Equal?
stricmp(a, b) == 0
Ignore case
MSVC
_stricmp(a, b)
Documented
POSIX
strcasecmp(a, b)
Linux/macOS
Exact
strcmp(a, b)
Case-sensitive
Hands-On
Examples Gallery
Examples target Windows/MSVC with <string.h>. On Linux or macOS, replace stricmp with strcasecmp and include <strings.h>.
📚 Getting Started
Compare two strings and check whether they match ignoring case.
Example 1 — Case-Insensitive Equality
"Hello, World!" and "hello, world!" compare as equal.
C
#include <stdio.h>
#include <string.h>
int main(void) {
const char *s1 = "Hello, World!";
const char *s2 = "hello, world!";
int result = _stricmp(s1, s2);
if (result == 0) {
printf("The strings are equal (ignoring case).\n");
} else if (result < 0) {
printf("s1 is less than s2.\n");
} else {
printf("s1 is greater than s2.\n");
}
return 0;
}
📤 Output:
The strings are equal (ignoring case).
How It Works
Every letter pair matches after case folding. Punctuation and spaces must still match exactly—only letter case is ignored.
Example 2 — Different Words Still Fail
Case insensitivity does not make different words equal.
C
#include <stdio.h>
#include <string.h>
int main(void) {
const char *a = "Hello";
const char *b = "Help";
if (_stricmp(a, b) == 0) {
printf("Match\n");
} else {
printf("No match (letters differ at 'l' vs 'p').\n");
}
return 0;
}
📤 Output:
No match (letters differ at 'l' vs 'p').
How It Works
After matching "Hel", the next characters 'l' and 'p' differ even ignoring case.
📈 Practical Patterns
Commands, comparison with strcmp, and cross-platform wrappers.
A macro or inline function hides platform differences so the rest of your program calls one name. This is a common pattern in cross-platform C libraries.
Applications
🚀 Common Use Cases
CLI commands — accept help, HELP, or Help.
Yes/No prompts — match y, Y, yes, YES.
Config keys — tolerate case in simple INI-style files (with care).
Filename checks — on case-insensitive file systems.
Windows-only tools — natural fit when targeting MSVC without POSIX.
🧠 How stricmp() Works
1
Read s1 and s2
Both must be null-terminated C-strings.
Input
2
Fold letter case
Compare bytes after ASCII-style upper/lower folding.
Fold
3
Return sign or zero
Same convention as strcmp.
Result
=
⚖️
int result
0 for equal ignoring case; otherwise less or greater.
Important
📝 Notes
Not ISO C—use strcasecmp on POSIX or a wrapper for portability.
MSVC prefers the name _stricmp in documentation.
ASCII-centric rules—not full Unicode or locale collation.
Do not pass NULL pointers—behavior is undefined.
Not for password comparison or security-sensitive equality.
Performance
⚡ Optimization
Runtime libraries optimize case-insensitive compares for typical string lengths. For hot paths, avoid repeated comparisons of the same literals—normalize input once or intern common commands.
Wrap Up
Conclusion
stricmp() (and _stricmp) is the Windows-friendly way to compare strings without caring about letter case. On POSIX systems use strcasecmp(), and wrap both when building cross-platform code.
Continue with strchr() to find the first occurrence of a character in a string.
Use _stricmp(a, b) == 0 on Windows for case-insensitive equality
Include <string.h> on Microsoft toolchains
Wrap with strcasecmp on POSIX in shared code
Use for user commands and human-entered text
Keep using strcmp when exact bytes matter
❌ Don’t
Assume stricmp exists on every compiler
Compare passwords case-insensitively
Expect locale-aware sorting for accented characters
Pass non-null-terminated buffers
Mix up stricmp with _strnicmp length limits
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about stricmp()
Use these points when comparing strings in C on Windows.
5
Core concepts
⚖️01
Ignore Case
A equals a.
Basics
📝02
0 = Match
Like strcmp.
Return
🔢03
Windows
_stricmp.
API
📈04
User Input
Commands.
Use case
💬05
vs strcasecmp
POSIX twin.
Compare
❓ Frequently Asked Questions
stricmp() compares two null-terminated C-strings without regard to letter case. It returns 0 when they match ignoring case, a negative value if s1 is less than s2, or a positive value if s1 is greater—using the same sign convention as strcmp().
On Microsoft Windows with MSVC, include <string.h>. The documented name is often _stricmp(); stricmp may be available as a compatibility alias. It is not part of ISO C.
They perform the same job—case-insensitive comparison. strcasecmp() is the POSIX name in <strings.h> on Linux and macOS. stricmp() / _stricmp() is the Microsoft-style name on Windows.
strcmp() is case-sensitive. stricmp() treats 'A' and 'a' as equal. Use strcmp for exact tokens; use stricmp for user-entered commands and names.
Microsoft documents _stricmp as the preferred portable name within their toolchain. stricmp exists on many Windows compilers as an alias. Check your compiler manual and enable the right warning levels for deprecated names.
No. Case-insensitive comparison is wrong for secrets, and neither stricmp nor strcmp provides timing-attack-resistant comparison. Use dedicated constant-time helpers for security-sensitive equality checks.
Did you know?
Microsoft also provides _strnicmp for bounded case-insensitive comparison—the Windows counterpart to POSIX strncasecmp. Pair bounded compares with length checks when matching untrusted input.