wcspbrk() function in C/C++

The wcspbrk() is a built-in function in C/C++ which searches for a set of wide characters present in a wide string in another wide string. It is defined within the cwchar header file of C++.

Syntax:

wcspbrk(dest, src)

Parameters: The function has two parameters as shown below.



  • dest: It specifies to the null terminated wide string to be searched.
  • src: It specifies to a null terminated wide string containing the characters to search for.

Return Value: The function returns two values as follows:

  • If there are one or more than one common wide characters, in dest and src, the function returns the pointer to the first wide character in dest that is also in src.
  • If no wide characters is common in src & dest, a null pointer is returned.

Below programs illustrate the above function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// wcspbrk() function
#include <cwchar>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t src[] = L"Ishwar Gupta";
    wchar_t dest[] = L"GeeksforGeeks";
    wchar_t* s = wcspbrk(dest, src);
    int pos;
  
    if (s) {
        pos = s - dest;
        wcout << L"First occurrence in \"" << dest 
        << L"\" is at position " << pos << endl;
    }
    else
        wcout << L"No number found in \"" << dest << "\"";
  
    return 0;
}

chevron_right


Output:

First occurrence in "GeeksforGeeks" is at position 0

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// wcspbrk() function
#include <cwchar>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t src[] = L"123";
    wchar_t dest[] = L"Hello World";
    wchar_t* s = wcspbrk(dest, src);
    int pos;
  
    if (s) {
        pos = s - dest;
        wcout << L"First occurrence in \"" << dest 
        << L"\" is at position " << pos << endl;
    }
    else
        wcout << L"No common wide character";
  
    return 0;
}

chevron_right


Output:

No common wide character


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

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 :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.