Open In App

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.



Return Value: The function returns two values as follows:

Below programs illustrate the above function. Program 1






// 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;
}

Output:
First occurrence in "GeeksforGeeks" is at position 0

Program 2




// 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;
}

Output:
No common wide character

Article Tags :