CKTIS / C
wcsstr — finding a substring in a wide string
wcsstr finds the first occurrence of a wide substring. It returns a pointer to the match, or NULL when no match exists.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <wchar.h>
QWchar_t *wcsstr(QWchar_t *s1, const wchar_t *s2);wcsstr from <wchar.h> searches s1 for the sequence s2, excluding the pattern's terminating L'\0'. An empty s2 yields s1; the result points into the existing string, not a copy.
Both arguments must point to valid strings terminated by L'\0'. NULL and unterminated arrays cause undefined behavior. Check that the result is not NULL before using it.
In C23 notation, QWchar_t is a standard placeholder, not a type to declare: the result preserves the const qualification of s1 elements. For const wchar_t * it returns const wchar_t *; for wchar_t * it returns wchar_t *.
Examples
#include <stddef.h>
#include <stdio.h>
#include <wchar.h>
int main(void)
{
const wchar_t text[] = L"red blue blue";
const wchar_t *match = wcsstr(text, L"blue");
if (match != NULL) {
printf("index=%td\n", match - text);
}
printf("missing=%d\n", wcsstr(text, L"green") == NULL);
printf("empty=%d\n", wcsstr(text, L"") == text);
return 0;
}
Result
index=4 missing=1 empty=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.