wcswcs() — Locate wide-character substring in wide-character string

Standards

Standards / Extensions C or C++ Dependencies

ISO C Amendment
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3

both  

Format

#include <wchar.h>

wchar_t *wcswcs(const wchar_t *string1, const wchar_t *string2);

General description

Locates the first occurrence in the string pointed to by string1 of the sequence of wide characters (excluding the terminating wide NULL character) in the string pointed to by string2.

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.

Note: The wcswcs() function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The wcsstr() function is preferred for portability.

Returned value

If successful, wcswcs() returns a pointer to the located string.

If string2 points to a string with zero length, wcswcs() returns string1.

If the string is not found, wcswcs() returns NULL.

Example

CELEBW26
⁄* CELEBW26

   This example finds the first occurrence of the wide character string pr
   in buffer1, using wcswcs().

 *⁄
#include <stdio.h>
#include <wcstr.h>

#define SIZE 40

int main(void)
{
  wchar_t buffer1[SIZE] = L"computer program";
  wchar_t *ptr;
  wchar_t *wch = L"pr";

  ptr = wcswcs( buffer1, wch );
  printf( "The first occurrence of %ls in '%ls' is '%ls'\n",
                          wch, buffer1, ptr );
}
Output:
The first occurrence of pr in 'computer program' is 'program'

Related information