vfwprintf() — Format Argument Data as Wide Characters and Write to a Stream
Format
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
int vfwprintf(FILE *stream, const wchar_t *format, va_list arg);
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE and LC_NUMERIC categories of the current locale. The behavior might also be affected by the LC_UNI_CTYPE and LC_UNI_NUMERIC categories of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Integrated File System Interface
This function is not available when SYSIFCOPT(*NOIFSIO) is specified on the compilation command.
Wide Character Function
See Wide Characters for more information.
Description
The vfwprintf()
function
is equivalent to the fwprintf()
function,
except that the variable argument list is replaced by arg,
which the va_start macro (and possibly subsequent va_arg calls) will
have initialized. The vfwprintf()
function
does not invoke the va_end macro.
Because the functions vfwprintf()
, vswprintf()
,
and vwprintf()
invoke
the va_arg macro, the value of arg after the return is unspecified.
Return Value
The vfwprintf()
function
returns the number of wide characters that are written to the output
buffer, not counting the ending null wide character or a negative
value if an error was encountered. If n or more wide characters are
requested to be written, a negative value is returned.
Example
vout()
function,
which takes a variable number of arguments and uses vfwprintf()
to
print them to a file. #include <wchar.h>
#include <stdarg.h>
#include <locale.h>
void vout (FILE *stream, wchar_t *fmt, ...);
const char ifs_path [] = "/tmp/myfile";
int main(void) {
FILE *stream;
wchar_t format [] = L"%lc";
setlocale(LC_ALL, "POSIX");
if ((stream = fopen (ifs_path, "w")) == NULL) {
printf("Could not open file.\n");
return (-1);
}
vout (stream, format, L'a');
fclose (stream);
/***********************************************
The contents of output file /tmp/myfile should
be a wide char 'a' which in the "POSIX" locale
is '0081'x.
*/
return (0);
}
void vout (FILE *stream, wchar_t *fmt, ...)
{
va_list arg_ptr;
va_start (arg_ptr, fmt);
vfwprintf (stream, fmt, arg_ptr);
va_end (arg_ptr);
}
Related Information
- printf() — Print Formatted Characters
- fprintf() — Write Formatted Data to a Stream
- vfprintf() — Print Argument Data to Stream
- vprintf() — Print Argument Data
- btowc() — Convert Single Byte to Wide Character
- mbrtowc() — Convert a Multibyte Character to a Wide Character (Restartable)
- fwprintf() — Format Data as Wide Characters and Write to a Stream
- vswprintf() — Format and Write Wide Characters to Buffer
- vwprintf() — Format Argument Data as Wide Characters and Print
- <stdarg.h>
- <stdio.h>
- <wchar.h>