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:

Return value: The function returns two value as below:



Below programs illustrate the above function:
Program-1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustarte
// wmemchr() function
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // initialize the string to be scanned
    wchar_t ptr[] = L"GeeksForGeeks";
  
    // character to be searched for
    wchar_t ch = L'o';
  
    // length, till the character to be search for is 8
    // run the function to check if the character is present
    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;
}
chevron_right

Output:
'o' is present in first 8 characters of "GeeksForGeeks"

Program 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustarte
// wmemchr() function
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // initialize the string to be scanned
    wchar_t ptr[] = L"GFG";
  
    // character to be searched for
    wchar_t ch = L'p';
  
    // length, till the character to be search for is 3
    // run the function to check if the character is present
    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;
}
chevron_right

Output:
'p' is not present in first 3 characters of "GFG"

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.





Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
C
Practice Tags :