gtpc2m9f | C/C++ Language Support User's Guide |
This function formats and writes data to a buffer.
Format
#include <stdarg.h> #include <stdio.h> int vsprintf(char *target-string, const char *format., va_listst arg_ptr);
The vsprintf function is similar to the sprintf function except that arg_ptr points to a list of arguments whose number can vary from call to call in the program. In contrast, the sprintf function can have a list of arguments, but the number of arguments in that list is fixed when you compile the program. For a specification of the format string, see fprintf, printf, sprintf-Format and Write Data.
Normal Return
If there is no error, the vsprintf function returns the number of characters written to target-string.
Error Return
If an error occurs, the vsprintf function returns a negative value.
Programming Considerations
None.
Examples
The following example assigns a variable number of strings to string and prints the string that is the result using the vsprintf function.
#include <stdarg.h> #include <stdio.h> void vout(char *string, char *fmt, ...); char fmt1 [] = "%s %s %s\n"; int main(void) { char string[100]; vout(string, fmt1, "Sat", "Sun", "Mon"); printf("The string is: %s\n", string); } void vout(char *string, char *fmt, ...) { va_list arg_ptr; va_start(arg_ptr, fmt); vsprintf(string, fmt, arg_ptr); va_end(arg_ptr); }
Output
The string is: Sat Sun Mon
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.