Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is vwprintf() in C?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

RELATED TAGS

c

CONTRIBUTOR

Syed Muhammad Ali Mustafa
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring