C stricmp() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
string.h

Definition

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");
CallWhat 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

ParameterDescription
s1Required. The first C-string.
s2Required. The second C-string.

Return Value

Return ValueDescription
0The strings match when letter case is ignored.
Less than 0The first string comes first.
Greater than 0The 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;
}

How It Works

  1. Compare both strings. Letters are matched after folding case.
  2. Return is zero. Every character pair matches when case is ignored.
  3. Branch on == 0. That is the usual “are these the same?” test.
  4. 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.

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

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

    if (stricmp(input, "quit") == 0) {
        printf("command: quit\n");
    } else {
        printf("unknown command\n");
    }

    return 0;
}

How It Works

  1. User typed mixed case. "Quit" is not identical to "quit".
  2. stricmp ignores case. The compare still returns 0.
  3. One branch handles all casings. You do not need separate tests for each spelling.
  4. Good for menus. Commands and yes/no answers often want this behavior.

Example 3 — Ordering With Sign of Return

Nonzero results still carry order information after case folding. Do not assume a specific magnitude—only the sign.

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

int main(void) {
    int r = stricmp("apple", "Banana");

    if (r < 0) {
        printf("apple comes first\n");
    } else if (r > 0) {
        printf("Banana comes first\n");
    } else {
        printf("equal\n");
    }

    return 0;
}

How It Works

  1. Fold case first. Compare as if both were lowercased.
  2. First letters decide. 'a' sorts before 'b'.
  3. Return is negative. So "apple" is less than "Banana".
  4. Test the sign. Portable code uses < 0 / > 0, not exact integers.

Frequently Asked Questions

stricmp() compares two C-strings without caring about letter case. Matching letters return 0.
Both are required. s1 and s2 are the C-strings to compare.
0 when they match ignoring case. Otherwise the sign tells which comes first.
No. On Windows prefer _stricmp. On POSIX use strcasecmp.
No. strcmp() treats 'A' and 'a' as different.

Next: strchr()

Find the first occurrence of a character inside a C-string.

strchr() tutorial →

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.

9 people found this page helpful