[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


vfprintf

Write formatted output to a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdarg.h>
#include <stdio.h>
int vfprintf(FILE *stream,
   const char *format,va_list arg);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  
format  
const char *  
The format string  
arg  
va_list  
The variable argument list  

Remarks:

The vfprintf() function works identically to the fprintf() function. Instead of the variable list of arguments that can be passed to fprintf(), vfprintf() accepts its arguments in the array arg of type va_list which must have been initialized by the va_start() macro from the stdarg.h header file. The vfprintf() does not invoke the va_end macro.


NOTE

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.

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.

See Also:

"Wide Character and Byte Character Stream Orientation"

"fprintf"

"printf"

"Overview of stdarg.h"

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;
}


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000