PrintfFprintfSprintfformatted output
#include <stdio.h>
printfchar *control...fprintfFILE *fpchar *control...sprintfchar *stringchar *control...Description
Thse three functions are used to place numbers and strings on
the output in formatted, human readable form.
Fprintf places its output on the file "fp", printf on the
standard output, and sprintf in the buffer pointed to by
"string". NOTE that it is the user's responsibility to ensure
that this buffer is large enough.
The "control" string determines the format, type, and number
of the following arguments expected by the function. If the
control does not match the arguments correctly, the results
are unpredictable.
The control may contain characters to be copied directly to
the output and/or format specifications. Each format
specification causes the function to take the next successive
argument for output.
A format specification consists of a "%" character followed by
(in this order):
An optional minus sign ("-") that means left justification
in the field.
An optional string of digits indication the field width
required. The field will be at least this wide and may be
wider if the conversion requires it. The field will be
padded on the left unless the above minus sign is present,
in which case it will be padded on the right. The padding
character is, by default, a space, but if the digit string
starts with a zero ("0"), it will be "0".
An optional dot (".") and a digit string, the precision,
which for floating point arguments indicates the number
of digits to follow the decimal point on conversion, and
for strings, the maximum number of characters from the
string argument are to be printed.
An optional character "l" indicates that the following
"d","x", or "o" is the specification of a long integer
argument. NOTE that in order for the printing of long
integers to take place, the source code must have in it
somewhere the statement pflinit(), which causes routines
to be linked from the library.
A conversion character which shows the type of the
argument and the desired conversion. The recognized
conversion characters are:
d,o,x,XThe argument is an integer and the
conversion is to decimal, octal, or
hexadecimal, respectively. "X" prints hex
and alpha in upper case.uThe argument is an integer and the
conversion is to an unsigned decimal in
the range 0 to 65535.fThe argument is a double, and the form of
the conversion is "[-]nnn.nnn". Where the
digits after the decimal point are
specified as above. If not specified, the
precision defaults to six digits. If the
precision is 0, no decimal point or
following digits are printed.e,EThe argument is a double and the form of
the conversion is "[-]n.nnne(+or-)nn"; one
digit before the decimal point, and the
precision controls the number following.
"E" prints the "e" in upper case.g,GThe argument is a double, and either the
"f" format or the "e" format is chosen,
whichever is the shortest. If the "G"
format is used, the "e" is printed in
upper case.
NOTE in each of the above double conversions, the last digit is
rounded.
ALSO NOTE that in order for the printing of floats or doubles
to take place, the source program must have the statement
pffinit() somewhere.
cThe argument as a character.sThe argument is a pointer to a string.
Characters from the string are printed up
to a null character, or untill the number of
characters indicated by the precision have
been printed. If the precision is 0 or
missing, the characters are not counted.%No argument corresponding; "%" is printed.See Also
Kernighan & Ritchie pages 145-147.
putc(),
scanf()