Write formatted output to a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdarg.h>
#include <stdio.h>
int vfprintf(FILE *stream,  
const char *format,va_list arg);
Parameters for this facility are:
NOTE
For specifications concerning the output control string and conversion specifiers please see: "Output Control String and Conversion Specifiers."
Return:
vfprintf() returns the number of characters written or EOF if it failed.
"Wide Character and Byte Character Stream Orientation"
Example of vfprintf() usage.:#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int fpr(FILE *, char *, ...);
int main(void)
{
FILE *f;
static char name[] = "foo";
int a = 56, result;
double x = 483.582;
// create a new file for output
if (( f = fopen(name, "w")) == NULL) {
printf("Can't open %s.\n", name);
exit(1);
}
// format and output a variable number of arguments
// to the file
result = fpr(f, "%10s %4.4f %-10d\n", name, x, a);
// close the file
fclose(f);
return 0;
}
// fpr() formats and outputs a variable
// number of arguments to a stream using
// the vfprintf() function
int fpr(FILE *stream, char *format, ...)
{
va_list args;
int retval;
va_start(args, format); // prepare the arguments
retval = vfprintf(stream, format, args);
// output them
va_end(args); // clean the stack
return retval;
}