gtpc2m9e | C/C++ Language Support User's Guide |
This function formats and writes data to the standard output stdout stream.
Format
#include <stdarg.h> #include <stdio.h> int vprintf(const char *format, va_list arg_ptr);
The vprintf function is similar to printf except that arg_ptr points to a list of arguments whose number can vary from call to call in the program. These arguments must be initialized by va_start for each call. In contrast, printf 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.
The vprintf function has the same restriction as any write operation for a read immediately following a write, or a write immediately following a read. Between a write and a subsequent read, there must be an intervening flush or reposition. Between a read and a subsequent write, there must be an intervening reposition unless an end-of-file (EOF) has been reached.
Normal Return
If there is no error, vprintf returns the number of characters written to stdout.
Error Return
If an error occurs, vprintf returns a negative value.
Programming Considerations
Examples
The following example prints out a variable number of strings to stdout using vprintf.
#include <stdarg.h> #include <stdio.h> void vout(char *fmt, ...); char fmt1 [] = "%s %s %s %s %s \n"; int main(void) { vout(fmt1, "Mon", "Tues", "Wed", "Thurs", "Fri"); } void vout(char *fmt, ...) { va_list arg_ptr; va_start(arg_ptr, fmt); vprintf(fmt, arg_ptr); va_end(arg_ptr); }
Output
Mon Tues Wed Thurs Fri
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.