.TH sprintf() "" "" "STDIO Function (libc)"
.PC "Format output"
.B "#include <stdio.h>"
\fBint sprintf(\fIstring\^\fB, \fIformat \fR[ \fB, \fIarg \fR] .\^.\^.\^\fB)\fR
\fBchar *\fIstring\^\fB, \fI*format\^\fB;\fR
.PP
.B sprintf()
formats and prints a string.
It resembles the function
.BR printf() ,
except that it writes its output into the memory location pointed to by
.IR string ,
instead of to the standard output.
.PP
.B sprintf()
reads the string pointed to by
.I format
to specify an output format for each
.IR arg ;
it then writes every
.I arg
into
.IR string ,
which it ends with a null character.
For a detailed discussion of
.BR sprintf() 's
formatting codes, see
.BR printf() .
.PP
If it wrote the formatted string correctly,
.B sprintf()
returns the number of characters written.
Otherwise, it returns a negative number.
.SH Example
For an example of this function, see the entry for \fBsscanf()\fR.
.SH "See Also"
.Xr "printf()," printf
.Xr "fprintf()," fprintf
.Xr "libc," libc
.Xr "vsprintf()" vsprintf
.br
\*(AS, \(sc7.9.6.5
.br
\*(PX Standard, \(sc8.1
.SH Notes
The output
.I string
passed to
.B sprintf()
must be large enough to hold all output characters.
.PP
Because C does not perform type checking,
it is essential that each argument match its
format specification.
