C stricmp() Function

Last Updated:

C stricmp()

The stricmp() function compares the characters of two strings.

The characters of the strings may be in lower case or upper case, this function doesn't discriminates between them, i.e, Both 'A' and 'a' are equal.

The stricmp() function starts comparison character by character starting from the first character until the characters in both strings are equal or a NULL character is encountered.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "abcd"; char str2[] = "ABCD"; // case insensitive match int res = stricmp(str1, str2); if(res == 0) printf("str1 is equal to str2"); else if(res > 0) printf("str1 is greater than str2"); else printf("str1 is less than str2"); return 0; }

Syntax

int stricmp(char *str1, char *str2)

Parameter Values

ValueTypeExplanation
str1 Required Specifies the string 1
str2 Required Specifies the string 2

Return Value

ValueExplanation
-1 If str1 is less than str2
0 If str1 is equal to str2
1 If str1 is greater than str2

Share this Page

Meet the Author