vfprintf() — Print Argument Data to Stream
Format
#include <stdarg.h>
#include <stdio.h>
int vfprintf(FILE *stream, const char *format, va_list arg_ptr);
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 category 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.
Description
The vfprintf()
function
formats and writes a series of characters and values to the output stream.
The vfprintf()
function
works just like the fprintf()
function,
except that arg_ptr points to a list of
arguments whose number can vary from call to call in the program.
These arguments should be initialized by va_start for
each call. In contrast, the fprintf()
function
can have a list of arguments, but the number of arguments in that
list is fixed when you compile the program.
The vfprintf()
function
converts each entry in the argument list according to the corresponding
format specifier in format. The format has
the same form and function as the format string for the printf()
function.
Return Value
If successful, vfprintf()
returns
the number of bytes written to stream. If
an error occurs, the function returns a negative value.
Example
#include <stdarg.h>
#include <stdio.h>
void vout(FILE *stream, char *fmt, ...);
char fmt1 [] = "%s %s %s\n";
int main(void)
{
FILE *stream;
stream = fopen("mylib/myfile", "w");
vout(stream, fmt1, "Sat", "Sun", "Mon");
}
void vout(FILE *stream, char *fmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, fmt);
vfprintf(stream, fmt, arg_ptr);
va_end(arg_ptr);
}
/****************** Output should be similar to: ****************
Sat Sun Mon
*/
Related Information
- fprintf() — Write Formatted Data to a Stream
- printf() — Print Formatted Characters
- va_arg() – va_copy() – va_end() – va_start() — Handle Variable Argument List
- vprintf() — Print Argument Data
- vsprintf() — Print Argument Data to Buffer
- vwprintf() — Format Argument Data as Wide Characters and Print
- <stdarg.h>
- <stdio.h>