wcsstr() — Locate a wide character sequence
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C Amendment |
both |
Format
#include <wchar.h>
wchar_t *wcsstr(const wchar_t *__restrict__ wcs1,
const wchar_t *__restrict__ wcs2);
#define _XOPEN_SOURCE
#define _MSE_PROTOS
#include <wchar.h>
wchar_t *wcsstr(const wchar_t *__restrict__ wcs1,
const wchar_t *__restrict__ wcs2);
General description
Locates the first occurrence in the wide-character string pointed to by wcs1 of the sequence of wide characters (excluding the terminating NULL character) in the wide-character string pointed to by wcs2.
The behavior of this wide-character function is affected by the LC_CTYPE category of the current locale. If you change the category, undefined results can occur.
Special behavior for XPG4: If you define any feature test macro specifying XPG4 behavior before the statement in your program source file to include the wchar header, then you must also define the _MSE_PROTOS feature test macro to make the declaration of the wcsstr() function in the wchar header available when you compile your program. Please see Table 1 for a list of XPG4 and other feature test macros.
Returned value
If successful, wcsstr() returns a pointer to the located wide string. If wcs2 points to a wide-character string with zero length, wcsstr() returns wcs1.
If the wide-character string is not found, wcsstr() returns NULL.
Example
/* CELEBW20 */
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t *wcs1 = L"needle in a haystack";
wchar_t *wcs2 = L"hay";
wchar_t *result;
result = wcsstr(wcs1, wcs2);
/* result = a pointer to "hatstack" */
printf("result: `%S`\n", result);
}