Javatpoint Logo
Javatpoint Logo

Strcmpi() function in C

C is a programming language renowned for low-level control and efficiency. C has a wide range of functions for string manipulation that can be used to carry out operations like string comparison, concatenation, and copying. One such crucial function is Strcmpi(), which enables a case-insensitive comparison of two strings. In this article, we'll get into the specifics of the Strcmpi() function, including its syntax, use, and provided examples and corresponding results.


The Strcmpi() method has the following syntax:

The two strings being compared in this case are str1 and str2. An integer value that the function returns can be understood as follows:

  • The result indicates that str1 is smaller than str2 if the return value is less than 0.
  • If the return value is 0, then str1 and str2 are equivalent.
  • It is implied that str1 is larger than str2 if the return value is greater than 0.

Example 1:

Let's use a little piece of code to demonstrate how to use the Strcmpi() function:


The result of running the code is:

The strings are equal.


The relevant header files, stdio.h for input/output functions and string.h for string manipulation methods, are first included in the code above. After that, we define two strings, str1 and str2, each of which has the word "hello": str1 contains "Hello" and str2 contains "hello".

We use the strcmpi() function and supply the arguments str1 and str2 to it. The function returns an integer number, which we keep in the result variable, and compares the strings case-insensitively. Finally, we check the value of the result using conditional statements before displaying the relevant message. The Strcmpi() function compares strings without regard to case, therefore it regards "Hello" and "hello" as being equivalent.

Example 2:

Let's examine a few more instances to comprehend how the Strcmpi() method behaves in various circumstances.


The strings are equal.

Despite the case difference ("apple" and "Apple"), the Strcmpi() function treats both equally in this instance since it conducts a case-insensitive comparison.

Example 3:


str1 is greater than str2.


The Strcmpi() method compares "OpenAI" to "OpenAPI" in this illustration. The function gives a positive number because "AI" follows "API" in the alphabet, proving that str1 is bigger than str2.


In conclusion, the C language's Strcmpi() function provides a useful resource for case-insensitive string comparisons. It enables us to compare strings without considering the different character cases. Many different string manipulation jobs can be considerably aided by an understanding of its syntax, usage, and behavior. This feature enables programmers to construct programs that are more resilient and versatile.

Keep in mind that while the Strcmpi() function may be included in some C compilers, it might not be included in the standard C library. It's critical to confirm that this function is accessible and compatible with your development environment.

The Strcmpi() function makes case-insensitive string comparisons easier to handle for developers by ignoring case differences during string comparisons in C. Programmers can enhance the user experience by making their applications more user-friendly by using the Strcmpi() function. In order to ensure that commands or input variants are correctly recognized, it enables them to handle user input in a case-insensitive manner. Developers can improve the overall quality and usefulness of their C program by using the Strcmpi() method to construct code that effectively handles string comparisons while taking case-insensitivity into account.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA