stricmp, _mbsicmp, _wcsicmp

From RAD Studio
Jump to: navigation, search

Go Up to string.h Index


Header File

string.h, mbstring.h

Category

Memory and String Manipulation Routines

Prototype

<span class="codeInline">int stricmp(const char *s1, const char *s2);</span>
<span class="codeInline">int _wcsicmp(const wchar_t *s1, const wchar_t *s2);</span>
<span class="codeInline">int _mbsicmp(const unsigned char *s1, const unsigned char *s2);</span>

Description

Compares one string to another, without case sensitivity.

stricmp performs an unsigned comparison of s1 to s2, starting with the first character in each string and continuing with the next characters until:

  • The corresponding characters differ
  • Or the end of the strings is reached.

The comparison is not case-sensitive. stricmp returns a value (< 0, 0, or > 0) based on the result of comparing s1 (or part of it) to s2 (or part of it).

The routines stricmp and strcmpi are the same. strcmpi is implemented through a macro in string.h that translates calls from strcmpi to stricmp. Therefore, to use stricmp you must include the header file string.h for the macro to be available.

Note: In RAD Studio, the functions convert the strings to uppercase for comparison. This is different from other implementations, notably Visual C++ which lowercases for comparison.

Return Value

less than s2

< 0

the same as s2

== 0

greater than s2

> 0

Example

 
#include &lt;string.h&gt;
 #include &lt;stdio.h&gt;
 int main(void)
 {
    char *buf1 = "BBB", *buf2 = "bbb";
    int ptr;
    ptr = stricmp(buf2, buf1);
    if (ptr &gt; 0)
       printf("buffer 2 is greater than buffer 1\n");
    if (ptr &lt; 0)
       printf("buffer 2 is less than buffer 1\n");
    if (ptr == 0)
       printf("buffer 2 equals buffer 1\n");
    return 0;
 }

Portability

POSIX Win32 ANSI C ANSI C++

stricmp

+

+

+

_mbsicmp

+

_wcsicmp

+