In C, vfwprintf() prints a va_list as wide text to a stream. It belongs to the wide-character tools declared in <wchar.h>.
Use wchar_t for wide characters and prefix wide literals with L, as in L"Hello". The examples below use simple C Programming Tutorial patterns and print wide strings with %ls.
Syntax
The following concrete call shows the argument shape before the formal declaration.
C
vfwprintf(stream, format, args);
Call
What it does
vfwprintf(stream, format, args)
Prints a va_list as wide text to a stream in a typical call.
Include <wchar.h>. Add only the supporting headers actually used by your program.
Library declaration
int vfwprintf(FILE *restrict stream, const wchar_t *restrict format, va_list arg);
Parameters
Parameter
Description
stream
The FILE stream to read, write, inspect, or push back into.
format
A wide format string that controls printing or scanning.
arg
A va_list prepared by va_start in a variadic wrapper.
Return Value
Return Value
Description
Non-negative result
Success count, orientation, or status as defined by the function.
Negative / EOF
A conversion, input, output, or formatting failure.
C Examples
Example 1 — Forward one string
This example uses vfwprintf() to forward one string, then exposes the result so you can connect the call with its output.
C
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
static int print_to(FILE *stream, const wchar_t *format, ...) {
va_list args;
va_start(args, format);
int result = vfwprintf(stream, format, args);
va_end(args);
return result;
}
int main(void) {
print_to(stdout, L"%ls\n", L"Hello");
return 0;
}
Output
Hello
How It Works
Set up this case. The program prepares the exact input needed to forward one string.
Match the format and arguments.vfwprintf(stream, format, args) uses a wide format string and correctly typed values or pointers.
Read the normal result. The displayed output shows the direct result of the call for this input.
Interpret the output.Hello confirms the behavior demonstrated by this example.
Example 2 — Return the character count
This example uses vfwprintf() to return the character count, then exposes the result so you can connect the call with its output.
C
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
static int print_to(FILE *stream, const wchar_t *format, ...) {
va_list args;
va_start(args, format);
int result = vfwprintf(stream, format, args);
va_end(args);
return result;
}
int main(void) {
int written = print_to(stdout, L"value = %d\n", 42);
wprintf(L"written = %d\n", written);
return 0;
}
Output
value = 42
written = 11
How It Works
Choose the edge case. This example changes the input so you can see how vfwprintf() behaves for return the character count.
Match the format and arguments.vfwprintf(stream, format, args) uses a wide format string and correctly typed values or pointers.
Inspect the status or pointer. The program checks what the function returned before relying on output data.
Interpret the output.value = 42 / written = 11 confirms the behavior demonstrated by this example.
Example 3 — Forward mixed values
This example uses vfwprintf() to forward mixed values, then exposes the result so you can connect the call with its output.
C
#include <stdio.h>
#include <wchar.h>
#include <stdarg.h>
static int print_to(FILE *stream, const wchar_t *format, ...) {
va_list args;
va_start(args, format);
int result = vfwprintf(stream, format, args);
va_end(args);
return result;
}
int main(void) {
print_to(stdout, L"%ls %.1f\n", L"score", 9.5);
return 0;
}
Output
score 9.5
How It Works
Prepare a practical variation. The data is arranged specifically to forward mixed values.
Match the format and arguments.vfwprintf(stream, format, args) uses a wide format string and correctly typed values or pointers.
Notice the safety rule. The example keeps the count, destination capacity, stream state, and terminator requirements visible.
Interpret the output.score 9.5 confirms the behavior demonstrated by this example.
Frequently Asked Questions
vfwprintf() prints a va_list as wide text to a stream. It is part of the standard wide-character library.
Its parameters are stream, format, arg. stream: The FILE stream to read, write, inspect, or push back into. format: A wide format string that controls printing or scanning. arg: A va_list prepared by va_start in a variadic wrapper.
Non-negative result means success count, orientation, or status as defined by the function. Negative / EOF means a conversion, input, output, or formatting failure.
Include <wchar.h> for vfwprintf(). Include only the supporting headers used by your program, such as <stdio.h> for FILE or <stdarg.h> for va_list.
The wide format string must match every argument exactly. A wrong specifier or missing destination address causes undefined behavior.