vswscanf() Function in C/C++
Last Updated :
06 Mar, 2023
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:
- ws :Pointer to the null terminated wide string to read the data
- format :Pointer to a null-terminated wide character string that specifies how to read the input
- arg : A value identifying a variable arguments list initialized with va_start.
Return value: The function returns two value as below:
- on success, it returns the number of arguments successfully read.
- on failure, EOF is returned
Below programs illustrate the above function: Program 1 :
CPP
#include <bits/stdc++.h>
using namespace std;
void wideMatch( const wchar_t * ws, const wchar_t * format, ...)
{
va_list arg;
va_start (arg, format);
vswscanf(ws, format, arg);
va_end (arg);
}
int main()
{
setlocale (LC_ALL, "en_US.UTF-8");
wchar_t wideS[] = L"GFG";
wchar_t string[20];
wideMatch(wideS, L"%ls", string);
wprintf(L"Random Symbols are :\n");
for ( int i = 0; i < wcslen(string); i++) {
putwchar(string[i]);
putwchar( ' ' );
}
return 0;
}
|
Output:
Random Symbols are :
G F G
Program 2 :
CPP
#include <bits/stdc++.h>
using namespace std;
void WideString( const wchar_t * ws, const wchar_t * format, ...)
{
va_list arg;
va_start (arg, format);
vswscanf(ws, format, arg);
va_end (arg);
}
int main()
{
int value;
wchar_t wideS[] = L"100 websites of GeeksforGeeks";
WideString(wideS, L" %d %ls ", &value, wideS);
wprintf(L"Best: %ls\nQuantity: %d\n", wideS, value);
return 0;
}
|
Output:
Best: websites
Quantity: 100
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...