This vswprintf() function writes the wide string to the wide string buffer. A maximum of (len-1) wide characters are written to buffer which is followed by a null wide character.
int vswprintf( wchar_t* ws, size_t len, const wchar_t* format, va_list arg )
Parameters: The function accepts four mandatory parameters which are described below:
- ws: specifies the pointer to a given wide string buffer which will store the result
- len: specifies the maximum length of wide characters written back to the buffer including the terminating null character
- format: specifies the pointer to a null terminated wide string
- arg: specifies the value identifying a variable arguments list
Note: All format specifiers have the same meaning as in printf therefore, %lc shall be used to write a wide character ( and not %c ), as well as %ls shall be used for wide strings ( and not %s ).
Return value: The function returns two value as below:
- On success, the vswprintf() function returns number of wide characters written excluding the terminating null wide character.
- A negative number is returned on failure, including when the resulting string to be written to ws would be longer than n characters.
Below programs illustrate the above function:
Program 1 :
Some Latin letters : % & ' ( )
Program 2 :
GFG is : Geek for g
Note: If the resulting string would be longer than n-1 wide characters, the remaining characters are discarded and not stored.