wmemchr() function in C/C++
The wmemchr() function in C/C++ Locate character in block of wide characters. This function searches within the first num wide characters of the block pointed by ptr for the first occurrence of ch, and returns a pointer to it.
Syntax:
const wchar_t* wmemchr( const wchar_t* ptr, wchar_t ch, size_t num )
or
wchar_t* wmemchr( wchar_t* ptr, wchar_t ch, size_t num )
Parameters: The function accepts three mandatory parameters which are described below:
- ptr: specifies the pointer to the character array to be searched for.
- ch: specifies the character to be located.
- num: specifies the number of elements of type wchar_t to compare.
Return value: The function returns two value as below:
- On success, it returns a pointer to the location of character array.
- Otherwise, NULL pointer is returned.
Below programs illustrate the above function:
Program-1 :
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t ptr[] = L "GeeksForGeeks" ;
wchar_t ch = L 'o' ;
bool look = wmemchr(ptr, ch, 8);
if (look)
wcout << "'" << ch << "'" << L " is present in first "
<< 8 << L " characters of \"" << ptr << "\"" ;
else
wcout << "'" << ch << "'" << L " is not present in first "
<< 8 << L " characters of \"" << ptr << "\"" ;
return 0;
}
|
Output:
'o' is present in first 8 characters of "GeeksForGeeks"
Program 2 :
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t ptr[] = L "GFG" ;
wchar_t ch = L 'p' ;
bool look = wmemchr(ptr, ch, 3);
if (look)
wcout << "'" << ch << "'" << L " is present in first "
<< 3 << L " characters of \"" << ptr << "\"" ;
else
wcout << "'" << ch << "'" << L " is not present in first "
<< 3 << L " characters of \"" << ptr << "\"" ;
return 0;
}
|
Output:
'p' is not present in first 3 characters of "GFG"
Last Updated :
05 Feb, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...