Skip to content
Related Articles

Related Articles

Improve Article
wcsspn() function in C/C++ with Examples
  • Last Updated : 12 Sep, 2018

The wcsspn() is a built-in function in C/C++ which returns the length of maximum initial segment of the wide string that consists of characters present in another wide string. It is defined within the cwchar header file of C++.

Syntax:

wcsspn(des, src)

Parameters:The function accepts two mandatory parameters as described below.

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

Return Value: The function returns the length of the maximum initial segment of des that contains only the wide characters from wide string pointed to by src.

Below programs illustrate the above function.



Program 1:




// C++ program to illustrate the
// wcsspn() function
#include <cwchar>
#include <iostream>
using namespace std;
  
int main()
{
    wchar_t src[] = L"161106010";
    wchar_t des[] = L"6010IshwarGupta";
    int length = wcsspn(des, src);
  
    if (length > 0)
        wcout << des << L" contains " << 
                 length << L" initial numbers";
    else
        wcout << des << L" doesn't start with numbers";
  
    return 0;
}
Output:
6010IshwarGupta contains 4 initial numbers

Program 2:




// C++ program to illustrate the
// wcsspn() function
#include <cwchar>
#include <iostream>
using namespace std;
  
int main()
{
    wchar_t src[] = L"2018";
    wchar_t des[] = L"GeeksforGeeks";
    int length = wcsspn(des, src);
  
    if (length > 0)
        wcout << des << L" contains " << 
                 length << L" initial numbers";
    else
        wcout << des << L" doesn't start with numbers";
  
    return 0;
}
Output:
GeeksforGeeks doesn't start with numbers
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :