C String stricmp() Function

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
<string.h> (Windows)

What You’ll Learn

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.

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.

📝 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.
  • < 0s1 less than s2 (case-insensitive order).
  • > 0s1 greater than s2.

⚡ Quick Reference

s1s2stricmp result
"Hello, World!""hello, world!"0 (equal)
"Yes""no"> 0
"apple""Banana"< 0
WindowsPOSIX equivalentstricmp / _stricmpstrcasecmp
equality testany pairstricmp(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

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;
}

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;
}

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.

Example 3 — Match a User Command

Accept exit, EXIT, or Exit equally.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *input = "ExIt";

    if (_stricmp(input, "exit") == 0) {
        printf("Goodbye!\n");
    } else if (_stricmp(input, "help") == 0) {
        printf("Commands: help, exit\n");
    } else {
        printf("Unknown command: %s\n", input);
    }

    return 0;
}

How It Works

Console programs often compare user text to fixed commands. Case-insensitive matching avoids errors when Caps Lock is on.

Example 4 — stricmp() vs strcmp()

See how case sensitivity changes the result.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *a = "OpenAI";
    const char *b = "openai";

    printf("strcmp:  %d\n", strcmp(a, b));
    printf("_stricmp: %d\n", _stricmp(a, b));

    return 0;
}

How It Works

strcmp sees 'O' vs 'o' as different bytes. _stricmp folds case and reports equality.

Example 5 — Portable Case-Insensitive Compare

One wrapper selects the right function per platform.

C
#include <stdio.h>
#include <string.h>

#if defined(_WIN32)
  #define ci_compare _stricmp
#else
  #include <strings.h>
  #define ci_compare strcasecmp
#endif

int main(void) {
    const char *a = "Save";
    const char *b = "save";

    if (ci_compare(a, b) == 0) {
        printf("Same command (any case).\n");
    }

    return 0;
}

How It Works

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.

🚀 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.

📝 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.

⚡ 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.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about stricmp()

Use these points when comparing strings in C on Windows.

5
Core concepts
📝 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.

Continue the String Functions Series

Match strings ignoring case with stricmp() on Windows, then learn character search with strchr().

Next: strchr() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful