Format a character string array.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdarg.h>
#include <stdio.h>
int vsnprintf(char * s, size_t n,  
const char * format, va_list arg);
Parameters for this facility are:
For specifications concerning the output control string and conversion specifiers please see: "Output Control String and Conversion Specifiers."
Return: See Also:"Wide Character and Byte Character Stream Orientation"
Example Of Vsnprintf() Usage.:#include <stdarg.h>
#include <stdio.h>
int sp(char *, size_t, char *, ...);
int main()
{
int i = 1;
static char s[] = "Metrowerks";
char dest[50];
int retval;
retval = sp(dest, 5, "%s is number %d!", s, i);
printf("n too small, dest = |%s|, retval = %i\n", dest, retval);
retval = sp(dest, retval, "%s is number %d!", s, i);
printf("n right size, dest = |%s|, retval = %i\n", dest, retval);
return 0;
}
// sp() formats and outputs a variable number of arguments
// to a character string using the vsnprintf() function
int sp(char * s, size_t n, char *format,...)
{
va_list args;
int retval;
va_start(args, format); // prepare the arguments
retval = vsnprintf(s, n, format, args);
va_end(args); // clean the stack
return retval;
}
Output:
n too small, dest = |Metr|, retval = 23
n right size, dest = |Metrowerks is number 1|, retval = 23
[ 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