VMS Help
CRTL, wcswcs
*Conan The Librarian
|
Locates the first occurrence in the string pointed to by wstr1
of the sequence of wide characters in the string pointed to by
wstr2.
Format
#include <wchar.h>
wchar_t *wcswcs (const wchar_t *wstr1, const wchar_t *wstr2);
The wcswcs function has variants named _wcswcs32 and _wcswcs64
for use with 32-bit and 64-bit pointer sizes, respectively.
wstr1, wstr2
Pointers to null-terminated wide-character strings.
Pointer A pointer to the located wide-character
string.
NULL Indicates that the wide-character string was
not found.
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
/* This test uses wcswcs() to find the occurrence of each */
/* subwide-character string, string1 and string2, within */
/* the main wide-character string, lookin. */
#define BUF_SIZE 50
main()
{
static char lookin[] = "that this is a test was at the end";
char string1[] = "this",
string2[] = "the end";
wchar_t buffer[BUF_SIZE],
input_buffer[BUF_SIZE];
/* Convert lookin to wide-character format. */
/* Buffer and print it out. */
if (mbstowcs(buffer, lookin, BUF_SIZE) == (size_t)-1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
printf("Buffer to look in: %S\n", buffer);
/* Convert string1 to wide-character format and use */
/* wcswcs() to locate it within buffer */
if (mbstowcs(input_buffer, string1, BUF_SIZE) == (size_t)-1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
printf("this: %S\n", wcswcs(buffer, input_buffer));
/* Convert string2 to wide-character format and use */
/* wcswcs() to locate it within buffer */
if (mbstowcs(input_buffer, string2, BUF_SIZE) == (size_t)-1) {
perror("mbstowcs");
exit(EXIT_FAILURE);
}
printf("the end: %S\n", wcswcs(buffer, input_buffer));
exit(1);
}
Running this example produces the following results:
Buffer to look in: that this is a test was at the end
this: this is a test was at the end
the end: the end