1PRINTF(3)                  Linux Programmer's Manual                 PRINTF(3)
2
3
4

NAME

6       printf,  fprintf,  dprintf,  sprintf,  snprintf, vprintf, vfprintf, vd‐
7       printf, vsprintf, vsnprintf - formatted output conversion
8

SYNOPSIS

10       #include <stdio.h>
11
12       int printf(const char *restrict format, ...);
13       int fprintf(FILE *restrict stream,
14                   const char *restrict format, ...);
15       int dprintf(int fd,
16                   const char *restrict format, ...);
17       int sprintf(char *restrict str,
18                   const char *restrict format, ...);
19       int snprintf(char *restrict str, size_t size,
20                   const char *restrict format, ...);
21
22       #include <stdarg.h>
23
24       int vprintf(const char *restrict format, va_list ap);
25       int vfprintf(FILE *restrict stream,
26                   const char *restrict format, va_list ap);
27       int vdprintf(int fd,
28                   const char *restrict format, va_list ap);
29       int vsprintf(char *restrict str,
30                   const char *restrict format, va_list ap);
31       int vsnprintf(char *restrict str, size_t size,
32                   const char *restrict format, va_list ap);
33
34   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
35
36       snprintf(), vsnprintf():
37           _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
38               || /* Glibc <= 2.19: */ _BSD_SOURCE
39
40       dprintf(), vdprintf():
41           Since glibc 2.10:
42               _POSIX_C_SOURCE >= 200809L
43           Before glibc 2.10:
44               _GNU_SOURCE
45

DESCRIPTION

47       The functions in the printf() family produce output according to a for‐
48       mat  as  described  below.   The functions printf() and vprintf() write
49       output to stdout, the standard output stream; fprintf() and  vfprintf()
50       write  output  to  the  given  output  stream;  sprintf(),  snprintf(),
51       vsprintf(), and vsnprintf() write to the character string str.
52
53       The function dprintf() is the same as fprintf() except that it  outputs
54       to a file descriptor, fd, instead of to a stdio(3) stream.
55
56       The  functions snprintf() and vsnprintf() write at most size bytes (in‐
57       cluding the terminating null byte ('\0')) to str.
58
59       The  functions  vprintf(),  vfprintf(),  vdprintf(),  vsprintf(),   vs‐
60       nprintf()   are   equivalent  to  the  functions  printf(),  fprintf(),
61       dprintf(), sprintf(), snprintf(), respectively, except  that  they  are
62       called with a va_list instead of a variable number of arguments.  These
63       functions do not call the va_end macro.  Because they invoke the va_arg
64       macro, the value of ap is undefined after the call.  See stdarg(3).
65
66       All  of  these functions write the output under the control of a format
67       string that specifies how subsequent arguments (or  arguments  accessed
68       via the variable-length argument facilities of stdarg(3)) are converted
69       for output.
70
71       C99 and POSIX.1-2001 specify that the results are undefined if  a  call
72       to  sprintf(), snprintf(), vsprintf(), or vsnprintf() would cause copy‐
73       ing to take place between objects that overlap  (e.g.,  if  the  target
74       string  array and one of the supplied input arguments refer to the same
75       buffer).  See NOTES.
76