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


vsprintf

Write formatted output to a string.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int vsprintf(char *s, 
   const char *format, va_list arg);
Parameters:

Parameters for this facility are:

s  
char *  
A string to write to  
format  
const char *  
The format string  
arg  
va_list  
A variable argument list  

Remarks:

The vsprintf() function works identically to the sprintf() function. Instead of the variable list of arguments that can be passed to sprintf(), vsprintf() accepts its arguments in the array of type va_list processed by the va_start() macro from the stdarg.h header file.

For specifications concerning the output control string and conversion specifiers please see: "Output Control String and Conversion Specifiers."

Return:

vsprintf() returns the number of characters written to s not counting the terminating null character. Otherwise, EOF on failure.

See Also:

"Wide Character and Byte Character Stream Orientation"

"printf"

"sprintf"

"Overview of stdarg.h"

Example of vsprintf() usage.:
#include <stdio.h>
#include <stdarg.h>

int spr(char *, char *, ...);

int main(void)
{
	int a = 56;
	double x = 1.003;
	static char name[] = "Metrowerks";
	char s[50];

	// format and send a variable number of arguments
	// to character array s
	spr(s, "%10s\n %f\n %-10d\n", name, x, a);
	puts(s);

	return 0;
}

// spr() formats and sends a variable number of 
// arguments to a character array using the sprintf()
// function
int spr(char *s, char *format, ...)
{
	va_list args;
	int retval;

	va_start(args, format); // prepare the arguments
	retval = vsprintf(s, format, args);
	va_end(args);				// clean the stack
	return retval;
}

Output:
Metrowerks
 1.003000
 56 


[ 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