PRINTF(3) BSD Library Functions Manual PRINTF(3)
NAME
printf, fprintf, sprintf, snprintf, asprintf, dprintf, vprintf, vfprintf, vsprintf, vsnprintf, vasprintf, vdprintf -- formatted output con-
version
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#define _WITH_DPRINTF
#include <stdio.h>
int
printf(const char * restrict format, ...);
int
fprintf(FILE * restrict stream, 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 **ret, const char *format, ...);
int
dprintf(int fd, 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
vsnprintf(char * restrict str, size_t size, const char * restrict format, va_list ap);
int
vasprintf(char **ret, const char *format, va_list ap);
int
vdprintf(int fd, 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 given file descriptor; sprintf(), snprintf(), vsprintf(), and vsnprintf() write to the character string str; and asprintf() and
vasprintf() dynamically allocate a new string with malloc(3).
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.
The asprintf() and vasprintf() functions set *ret to be a pointer to a buffer sufficiently large to hold the formatted string. 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,
asprintf() and vasprintf() will return -1 and set ret to be a NULL pointer.
The snprintf() and vsnprintf() functions will write at most size-1 of the characters printed into the output string (the size'th character
then gets the terminating '