What is vwprintf() in C?

vwprintf() prints a wide-character string to stdout after formatting the data from the list of addresses passed as arguments.

Declaration

The declaration of vswprintf() is:

int vwprintf(const wchar_t * fmt,  va_list args);

Parameters

  • fmt: format specifiers of the input to be read.
  • args: points to the list of arguments in which the data will be stored.

Return value

If the write operation is successful, vwprintf() will return the number of wide characters written. On the other hand, if the write operation is not successful, a negative number is returned.

Code

The code snippet below demonstrates the use of vwprintf():

#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
void writeFormatted(const wchar_t * fmt, ... )
{
va_list args;
va_start(args, fmt);
vwprintf(fmt, args);
va_end(args);
}
int main ()
{
wchar_t str[] = L"%d mile is equal to %f %ls.\n";
int a = 1;
float x = 1.60934;
wchar_t wstr[] = L"kilometers";
writeFormatted(str, a, x, wstr);
return 0;
}

Explanation

In line 22, when the wide character string and the variable arguments are passed to the function, va_list is created to store the variable arguments. va_list formats the wide character string based on the parameters following the string, and then prints it.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved