Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

wcscmp — comparing wide strings

wcscmp compares null-terminated wchar_t strings; the sign of its result matters, not its exact value.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <wchar.h>
int wcscmp(const wchar_t *s1, const wchar_t *s2);

wcscmp from <wchar.h> lexicographically compares two wchar_t strings without modifying them. The first difference determines ordering by wchar_t values.

A result < 0, == 0, or > 0 means the first string is respectively less than, equal to, or greater than the second. Do not assume -1 or 1.

Both pointers must address readable strings terminated by L'\0'; NULL or a missing terminator causes undefined behavior. This is not linguistic sorting: use wcscoll for comparison according to LC_COLLATE.

Examples

#include <stdio.h>
#include <wchar.h>

int main(void)
{
    printf("%d\n", wcscmp(L"cat", L"cat") == 0);
    printf("%d\n", wcscmp(L"2", L"3") != 0);
    return 0;
}

Result

1
1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources