delorie.com/djgpp/doc/libc/libc_624.html | search |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#include <stdio.h> int printf(const char *format, ...); |
Sends formatted output from the arguments (...) to stdout
.
The format string contains regular characters to print, as well as conversion specifiers, which begin with a percent symbol. Each conversion speficier contains the following fields:
an optional flag, which may alter the conversion:
-
left-justify the field.
+
Force a +
sign on positive numbers.
space
To leave a blank space where a plus or minus sign would have been.
#
Alternate conversion - prefix octal numbers with 0
, hexadecimal
numbers with 0x
or 0X
, or force a trailing decimal point
if a floating point conversion would have omitted it.
0
To pad numbers with leading zeros.
A field width specifier, which specifies the minimum width of the field.
This may also be an asterisk (*
), which means that the actual
width will be obtained from the next argument. If the argument is
negative, it supplies a -
flag and a positive width.
An optional decimal point and a precision. This may also be an
asterisk, but a negative argument for it indicates a precision of zero.
The precision specifies the minimum number of digits to print for an
integer, the number of fraction digits for a floating point number (max
for g
or G
, actual for others), or the maximum number of
characters for a string.
An optional conversion qualifier, which may be:
hh
char
;
h
short
integers;
j
intmax_t
or uintmax_t
integers;
l
long
integers;
ll
long long
integers;
to specify long
doubles, although this is non-standard;
L
long
doubles;
t
ptrdiff_t
;
z
size_t
.
The conversion type specifier:
c
A single character.
d
A signed integer.
D
A signed long integer. This is non-standard and obsolete.
Please use ld
instead.
e
E
A floating point number (float or double). For long double, use
"Le"
or "LE"
. The exponent case matches the specifier
case. The representation always has an exponent.
f
A floating point number (float or double). For long double, use
"Lf"
. The representation never has an exponent.
g
G
A floating point number (float or double). For long double, use
"Lg"
or "LG"
. The exponent case matches the specifier
case. The representation has an exponent if it needs one.
i
A signed integer.
n
The next argument is a pointer to an integer, and the number of characters generated so far is stored in that integer.
o
A unsigned integer, printed in base 8 instead of base 10.
O
A unsigned long integer, printed in base 8 instead of base 10.
This is non-standard and obsolete. Please use lo
instead.
p
A pointer. This is printed with an x
specifier.
s
A NULL
-terminated string.
u
An unsigned integer.
U
An unsigned long integer. This is non-standard and obsolete.
Please use lu
instead.
x
X
An unsigned integer, printed in base 16 instead of base 10. The case of the letters used matches the specifier case.
%
A single percent symbol is printed.
The number of characters written.
ANSI/ISO C | C89; C99 (see note 1) (see note 2) |
POSIX | 1003.2-1992; 1003.1-2001 |
Notes:
hh
, j
, t
and z
conversion specifiers first appeared
in the ANSI C99 standard.
D
, O
and U
conversion types
are non-standard. gcc may generate warnings, if you use them.
printf("%-3d %10.2f%% Percent of %s\n", index, per[index], name[index]); |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2004 | Updated Apr 2004 |