strcmp, _mbscmp, wcscmp

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, Inline Routines

Prototype

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

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

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

Description

Compares one string to another.

strcmp 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.

Return Value

less than s2

< 0

the same as s2

== 0

greater than s2

> 0



Example

 #include <string.h>
 #include <stdio.h>
 int main(void)
 {
 char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
 int ptr;
 ptr = strcmp(buf2, buf1);
 if (ptr > 0)
       printf("buffer 2 is greater than buffer 1\n");
    else
       printf("buffer 2 is less than buffer 1\n");
    ptr = strcmp(buf2, buf3);
    if (ptr > 0)
       printf("buffer 2 is greater than buffer 3\n");
    else
       printf("buffer 2 is less than buffer 3\n");
    return 0;
 }

Portability

POSIX Win32 ANSI C ANSI C++

strcmp

+

+

+

+

_mbscmp

+

wcscmp

+

+

+

See Also