Next: vscanf, Previous: viscanf, Up: Stdio

### 4.51 `vprintf`, `vfprintf`, `vsprintf`—format argument list

Synopsis

         #include <stdio.h>
         #include <stdarg.h>
         int vprintf(const char *fmt, va_list list);
         int vfprintf(FILE *fp, const char *fmt, va_list list);
         int vsprintf(char *str, const char *fmt, va_list list);
         int vasprintf(char **strp, const char *fmt, va_list list);
         int vsnprintf(char *str, size_t size, const char *fmt,
             va_list list);

         int _vprintf_r(struct _reent *reent, const char *fmt,
             va_list list);
         int _vfprintf_r(struct _reent *reent, FILE *fp, const char *fmt,
             va_list list);
         int _vasprintf_r(struct _reent *reent, char **str,
             const char *fmt, va_list list);
         int _vsprintf_r(struct _reent *reent, char *str,
             const char *fmt, va_list list);
         int _vsnprintf_r(struct _reent *reent, char *str, size_t size,
             const char *fmt, va_list list);

Description
`vprintf`, `vfprintf`, `vasprintf`, `vsprintf` and `vsnprintf` are (respectively) variants of `printf`, `fprintf`, `asprintf`, `sprintf`, and `snprintf`. They differ only in allowing their caller to pass the variable argument list as a `va_list` object (initialized by `va_start`) rather than directly accepting a variable number of arguments.

Returns
The return values are consistent with the corresponding functions: `vasprintf`/`vsprintf` returns the number of bytes in the output string, save that the concluding `NULL` is not counted. `vprintf` and `vfprintf` return the number of characters transmitted. If an error occurs, `vprintf` and `vfprintf` return `EOF` and `vasprintf` returns -1. No error returns occur for `vsprintf`.

Portability
ANSI C requires all three functions.

Supporting OS subroutines required: `close`, `fstat`, `isatty`, `lseek`, `read`, `sbrk`, `write`.