What is vswscanf() in C?
vswscanf() reads a wide character string and stores the content of the string in a list of addresses. The list of addresses points to locations in memory in the specified format.
Declaration
The declaration of vswscanf() is as follows:
int vswscanf(const wchar_t * buffer, const wchar_t * format, va_list args);
Parameters
buffer: Pointer to the wide character string from which we read the input.format: Format specifiers of the input to be read.args: Pointer to the list of arguments in which data will be stored.
Return value
If the read operation from the input stream is successful, vswscanf() returns the number of arguments that are read. If the read operation is not successful,
Code
The code snippet below demonstrates the use of vswscanf():
#include <stdio.h>#include <wchar.h>#include <stdarg.h>void readFormatted(const wchar_t * str, const wchar_t * fmt, ...){va_list args;va_start(args, fmt);vswscanf(str, fmt, args);va_end(args);}int main (){wchar_t buffer[20];wchar_t buffer2[10];int x;float a;readFormatted(L"12 centimeters inches 30.48", L" %d %ls %ls %f ", &x, buffer, buffer2, &a);wprintf(L"%d %ls equal %.2f %ls.", x, buffer2, a, buffer);return 0;}
Explanation
The code in line 20 formats the wide-character string based on the parameters following the string (%d for integers, %ls for wide strings, and %f for float values) and then prints it in line 21.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved