gtpc2m9d | C/C++ Language Support User's Guide |
This function formats and writes data to a stream.
Format
#include <stdarg.h> #include <stdio.h> int vfprintf(FILE *stream, const char *format, v_list arg_ptr)
The vfprintf function is similar to the fprintf function 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, the fprintf 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.
The vfprintf 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, the vfprintf function returns the number of characters written to stream.
Error Return
If an error occurs, the vfprintf function returns a negative value.
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example prints out a variable number of strings to the myfile.dat file using vfprintf.
#include <stdarg.h> #include <stdio.h> void vout(FILE *stream, char *fmt, ...); char fmt1 [] = "%s %s %s\n"; int main(void) { FILE *stream; stream = fopen("myfile.dat", "w"); vout(stream, fmt1, "Sat", "Sun", "Mon"); } void vout(FILE *stream, char *fmt, ...) { va_list arg_ptr; va_start(arg_ptr, fmt); vfprintf(stream, fmt, arg_ptr); va_end(arg_ptr); }
Output
Sat Sun Mon
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.