fprintf writes formatted data to the file stream fp.
printf writes formatted data to stdout.
sprintf writes formatted data to buffer and 0 terminates it.
_snprintf function differs from sprintf in that it stores no
more than count characters in buffer.
Arguments are
interpreted according to the null-terminated format string.
The format string is a sequence of characters with embedded
conversion commands. Characters that are not part of the conversion
command are output. Conversion commands consist of:
'%'{flag}[field_width]['.' precision][size_and_dist] conversion_char
where a % always signifies the beginning of a conversion command.
To print a % use %%.
Flag Characters
-
| Means left justify the conversion
|
+
| Means that signed conversions always start with a + or -
|
(Space)
| Means that for positive conversions, the
conversion will start with a space. The + flag
overrides the (Space) flag.
|
#
| For x or X conversions, if the result is non-zero
then a 0x or 0X will be added to the front of it.
For o conversions, a leading 0 will be added.
|
For floating conversions (e, E, f, g, G),
a decimal point will always appear.
If it is g or G, then trailing 0's will not be truncated.
Field Width
This is a decimal integer controlling the minimum number of
characters printed. If the actual number of characters is less than the
field_width, it is padded with blanks. If the field_width digit
string begins with a 0, it is padded with a 0.
If the field_width is the character *, the actual field_width
value is taken from the next int arg. If the field_width is
negative, it is treated as if the - flag were given and the absolute
value of the field_width is used.
If there are more characters than allowed for by the field_width,
then the width is expanded appropriately.
Precision
Followed by a digit string specifying the precision of the conversion.
If no digits appear after the ., then the precision is taken as 0.
For integral conversions, this is the minimum number of digits.
For g and G, the precision gives the maximum number of digits appearing after
the decimal point.
For s, it is the maximum number of characters in a string.
If precision is the character *, the precision is taken from the
next int argument.
Size and Distance
Size and distance arguments are:
F
| __far pointer
|
N
| __near pointer
|
hh
| char integer
|
h
| short integer
|
l
| long integer
|
ll
| long long integer
|
j
| intmax_t or uintmax_t integer
|
z
| size_t integer
|
t
| ptrdiff_t integer
|
L
| long double
|
Conversion Character
One of the characters b, d, i, o, u, x, X,
a, A, f, F, e, E, g, G, c,
s, p, n, %.
Other characters cause undefined behavior.
b, d, i, o, u, x, X
| The argument is an integer and it is converted to a string
of digits according to the conversion character. b is
unsigned binary, o is unsigned octal, u is unsigned
decimal, x and X are unsigned hex, i and d are signed
decimal. For x, lower-case hex letters are used. For X,
upper-case ones are used. If no precision is specified, it
defaults to one. If there are fewer digits than precision,
leading spaces are placed before the digits. If argument
is 0 and precision is 0, no characters are printed.
|
c
| The least significant byte of the integer argument is
printed as a character.
|
e, E
| The argument is a double, and is printed in scientifc
notation, [-]d.dddddde+-dd. There is one digit before the
decimal point and precision digits after. The precision
defaults to 6. If the precision is 0, the decimal point is not
written. E is used for the exponent instead of e if the E
conversion character was specified. A minimum of two
digits will appear in the exponent.
|
f, F
| The argument is a double. It is converted to a decimal
string of the form [-]dd.dddd. The number of digits after
the decimal point is given by the precision, which
defaults to 6. If the precision is 0, no fractional digits or
decimal points appear. The F will result in INF or NAN rather
than inf or nan.
|
g, G
| The argument is a double. It is printed using f or e (or E
if G was specified) format, depending on the value of the
argument. e will be used if the exponent is less than -3 or greater than the
precision. The precision gives the number of significant
digits; it defaults to 6. The decimal point appears if
followed by a digit; trailing 0's are truncated.
|
a, A
| The argument is a floating point number, which is converted
to hex in the form [-]0x1.hhhhhp+-d, or 0 if the number is 0.hhhhh
are the digits of the mantissa in hex, and d is the exponent in decimal as
a power of 2. If no precision is specified, sufficient digits will
be generated to produce an exact value. Otherwise, it is rounded to
the specified precision. The A format will render the result in
all upper case. Trailing zeros are omitted. If the # flag is not
specified and the precision is 0, no decimal point is generated.
|
n
| The argument is a pointer to an int, into which is
written the number of characters printed so far. No
characters are generated or converted by this.
|
p
| The argument is a pointer that for far pointers is printed
as segment:offset or for near pointers as xxxx.
|
s
| The argument is a pointer to a string. The characters are
printed until a 0 character is encountered or the number
of characters specified in precision are printed. The
terminating 0 is not printed. The precision defaults to
32767.
|
%
| The % character is printed.
|