Open In App

vswscanf() Function in C/C++

The vfwscanf() function in C++ is used to read formatted data from wide string into variable argument list. It also reads wide character string from a wide string buffer. This function reads data from ws and stores them according to format into the locations pointed by the elements in the variable argument list identified by arg. It is defined in library file. Syntax :

int vswscanf( const wchar_t* ws, const wchar_t* format, va_list arg )

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 : 






// C++ program to illustrate the
// vswscanf() function
#include <bits/stdc++.h>
using namespace std;
 
// ws : pointer to the wide string
// format : to read the input
void wideMatch(const wchar_t* ws, const wchar_t* format, ...)
{
    va_list arg;
 
    // A function that invokes va_start
    // shall also invoke va_end before it returns.
    va_start(arg, format);
 
    // vswscanf() reads formatted data from wide
    // string into variable argument list
    vswscanf(ws, format, arg);
    va_end(arg);
}
 
// Driver code
int main()
{
    setlocale(LC_ALL, "en_US.UTF-8");
 
    // initialize the buffer
    wchar_t wideS[] = L"GFG";
    wchar_t string[20];
 
    wideMatch(wideS, L"%ls", string);
    wprintf(L"Random Symbols are :\n");
 
    // print all the symbols
    for (int i = 0; i < wcslen(string); i++) {
        putwchar(string[i]);
        putwchar(' ');
    }
 
    return 0;
}

Output:
Random Symbols are :
G F G

Program 2 : 




// C++ program to illustrate the
// vswscanf() function
 
#include <bits/stdc++.h>
using namespace std;
 
void WideString(const wchar_t* ws, const wchar_t* format, ...)
{
    va_list arg;
    // A function that invokes va_start
    // shall also invoke va_end before it returns.
    va_start(arg, format);
 
    // vswscanf() reads formatted data from wide
    // string into variable argument list
    vswscanf(ws, format, arg);
    va_end(arg);
}
 
// Driver code
int main()
{
    int value;
 
    // initialize the buffer
    wchar_t wideS[] = L"100 websites of GeeksforGeeks";
 
    WideString(wideS, L" %d %ls ", &value, wideS);
 
    // print all the symbols
    wprintf(L"Best: %ls\nQuantity: %d\n", wideS, value);
 
    return 0;
}

Output:
Best: websites
Quantity: 100

Article Tags :