RAD Studio |  |

stricmp, _mbsicmp, _wcsicmp

Header File

string.h, mbstring.h

Category

Memory and String Manipulation Routines

Prototype

int stricmp(const char *s1, const char *s2);

int _wcsicmp(const wchar_t *s1, const wchar_t *s2);

int _mbsicmp(const unsigned char *s1, const unsigned char *s2);

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 subsequent characters until the corresponding characters differ or until the end of the strings is reached. The comparison is not case sensitive.

It 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, in order to use stricmp, you must include the header file string.h for the macro to be available.

Return Value

less than s2 | < 0
the same as s2 | == 0
greater than s2 | > 0

Example

Copy Code

    #include <string.h>
    #include <stdio.h>
    int main(void)
    {
       char *buf1 = "BBB", *buf2 = "bbb";
       int ptr;
       ptr = stricmp(buf2, buf1);
       if (ptr > 0)
          printf("buffer 2 is greater than buffer 1\n");
       if (ptr < 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 |  | + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!