PRINTF(3) BSD Library Functions Manual PRINTF(3)
NAME
printf, fprintf, dprintf sprintf, snprintf, asprintf, vprintf, vfprintf, vsprintf, vdprintf, vsnprintf, vsnprintf_ss, vasprintf -- formatted
output conversion
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
int
printf(const char * restrict format, ...);
int
fprintf(FILE * restrict stream, const char * restrict format, ...);
int
dprintf(int fd, const char * restrict format, ...);
int
sprintf(char * restrict str, const char * restrict format, ...);
int
snprintf(char * restrict str, size_t size, const char * restrict format, ...);
int
asprintf(char ** restrict ret, const char * restrict format, ...);
#include <stdarg.h>
int
vprintf(const char * restrict format, va_list ap);
int
vfprintf(FILE * restrict stream, const char * restrict format, va_list ap);
int
vsprintf(char * restrict str, const char * restrict format, va_list ap);
int
vdprintf(int fd, const char * restrict format, va_list ap);
int
vsnprintf(char * restrict str, size_t size, const char * restrict format, va_list ap);
int
vsnprintf_ss(char * restrict str, size_t size, const char * restrict format, va_list ap);
int
vasprintf(char ** restrict ret, const char * restrict format, va_list ap);
DESCRIPTION
The printf() family of functions produces output according to a format as described below. The printf() and vprintf() functions write output
to stdout, the standard output stream; fprintf() and vfprintf() write output to the given output stream; dprintf() and vdprintf() write out-
put to the give file descriptor fd; sprintf(), snprintf(), vsprintf(), vsnprintf(), and vsnprintf_ss() write to the character string str; and
asprintf() and vasprintf() write to a dynamically allocated string that is stored in ret.
These functions write the output under the control of a format string that specifies how subsequent arguments (or arguments accessed via the
variable-length argument facilities of stdarg(3)) are converted for output.
vsnprintf_ss() is a signal-safe standalone version that does not handle floating point formats.
asprintf() and vasprintf() return a pointer to a buffer sufficiently large to hold the string in the ret argument. This pointer should be
passed to free(3) to release the allocated storage when it is no longer needed. If sufficient space cannot be allocated, these functions
will return -1 and set ret to be a NULL pointer. Please note that these functions are not standardized, and not all implementations can be
assumed to set the ret argument to NULL on error. It is more portable to check for a return value of -1 instead.
snprintf(), vsnprintf(), and vsnprintf_ss() will write at most size-1 of the characters printed into the output string (the size'th character
then gets the terminating '