| Table of Contents | Previous | Next |
The printf functions provide formatted output
conversions.
fprintf converts and writes output to
stream under the control of
format. The return value is the number of
characters written, or negative if an error occurred.
The format string contains two types of objects: ordinary
characters, which are copied to the output stream, and
conversion specifications, each of which causes conversion and
printing of the next successive argument to
fprintf. Each conversion specification
begins with the character % and ends with a
conversion character. Between the % and the
conversion character there may be, in order:
- |
specifies left adjustment of the converted argument in its field. | |
+ |
specifies that the number will be printed with a sign. | |
| space | if the first character is not a sign, a space will be prefixed. | |
0 |
for numeric conversions, specifies padding to the field width with leading zeros. | |
# |
specifies an alternate output form. For o,
the first digit will be zero. For x
or X, 0x or 0X
will be prefixed to a non-zero result. For
e,E, f,
g, and G, the output will
always have a decimal point; for g and
G, trailing zeros will be removed.
|
0 if the zero padding flag is
present.string |
the maximum number of characters to be printed | |
|
the number of decimal digits to be printed after the decimal point | |
g, G |
the number of significant digits | |
| integer | the minimum number of digits to be printed (leading
0s will be added to make up the necessary width)
|
h, l (letter ell), or
L. "h" indicates that the
corresponding argument is to be printed as short or
unsigned short; "l" indicates that the
argument is a long or unsigned long;
"L" indicates that the argument is a long
double.
Width or precision or both may be specified as *, in
which case the value is computed by converting the next argument(s)
which must be int.
The conversion characters and their meaning are shown
below. If the character after the % is not a
conversion character, the behaviour is undefined.
| CHARACTER | ARGUMENT TYPE; CONVERTED TO | |
|---|---|---|
d, i |
int; signed decimal notation.
| |
o |
int; unsigned octal notation (without a leading zero).
| |
x, X |
unsigned int; unsigned hexadecimal notation (without a
leading 0x or 0X), using
abcdef for 0x or ABCDEF for
0X.
| |
u |
int; unsigned decimal notation.
| |
c |
int; single character, after conversion to
unsigned char.
| |
s |
char *; characters from the string are printed
until a '\0' is reached or until the number of
characters indicated by the precision have been printed.
| |
f |
double; decimal notation of the form
[-]mmm.ddd, where the number of
d's is specified by the precision. The default
precision is 6; a precision of 0 suppresses the decimal point.
| |
e, E |
double; decimal notation of the form
[-]m.dddddde±xx or
[-]m.ddddddE±xx, where
the number of d's is specified by the precision.
The default precision is 6; a precision of 0 suppresses the decimal
point.
| |
g, G |
double; %e or %E is used
if the exponent is less than -4 or greater than or equal to the
precision; otherwise %f is used. Trailing zeros and
a trailing decimal point are not printed.
| |
p |
void *; print as a pointer
(implementation-dependent representation).
| |
n |
int *; the number of characters written so far by
this call to printf is written into the
argument. No argument is converted.
| |
% |
no argument is converted; print a %.
|
printf is equivalent to fprintf(stdout, ...).
sprintf is the same as printf except
that the output is written into the string s,
terminated with a '\0'. s must be
big enough to hold the result. The return count does not
include the '\0'.
vprintf, vfprintf, and
vsprintf are equivalent to the corresponding
printf functions, except that the variable argument
list is replaced by arg, which has been initialised
by the va_start macro and perhaps
va_arg calls. See <stdarg.h>.
| Table of Contents | Previous | Next |
Last modified: Thu Dec 7 11:37:50 2000