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

NAME

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

SYNOPSIS

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

DESCRIPTION

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