The wcsstr() function is defined in cwchar.h header file. The wcsstr() function finds the first occurrence of a source in a destination string.
Syntax:
wchar_t* wcsstr(const wchar_t* dest, const wchar_t* src);
Parameter: This method accepts the following parameters:
- src: It represents the pointer to the null terminating wide string to be search for.
- dest: It represents the pointer to the null terminating wide string in which we have to search.
Return Value: The return value of this method depends on:
- If src is not found than it returns NULL
- If src points to an empty string then destination is return
- If the src is found, the wcsstr() function returns the pointer to the first wide character of the src in dest.
Below program illustrate the above function:
Example 1: When the source is not found, null is returned
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t dest[] = L"Geeks Are Geeks";
wchar_t src[] = L"To";
wcout << wcsstr(dest, src);
return 0;
}
|
Example 2: When the source is empty, destination string is returned
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t dest[] = L"Geeks Are Geeks";
wchar_t src[] = L"";
wcout << wcsstr(dest, src);
return 0;
}
|
Example 3: When the source is found, the destination from the source is returned.
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t dest[] = L"Geeks Are Geeks";
wchar_t src[] = L"Are";
wcout << wcsstr(dest, L"Are");
return 0;
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Jun, 2022
Like Article
Save Article