printf

Formatted output to stdout.

int printf (char * format[, arguments]...);

Required Header
<stdio.h>

Return Value

This function returns the number of characters printed. -1 indicates an error.

Parameters

format

  The format control string

arguments

  Optional arguments specifying replacement values

Remarks

The printf function prints the format string to stdout, but also allows special characters to appear in the format string to specify that the next optional parameter should be used as the value to print. Special characters start with a percent sign (%) and can contain flags to control how the variable argument is printed. This is the form, and a list of supported special characters and options:

%[flags][width][.precision] [{h | hh | l | ll | L}]type

flags  description                             default
------ --------------------------------------- ----------------------------------
-      left align the field                    right align

+      if the field is a signed type use       only use a minus (-) when required
       a plus (+) or minus (-) sign.

0      add leading zeros to the output         no padding
       until the minumum width is reached

space  put space where a + would be printed    no space is printed

#      alter the format as follows:
       o x or X types have 0, 0x or 0X added
       e E or f forces a decimal point to appear
       g or G forces a decimal point, and no
       truncation of trailing zeros.
width specifies the minimum width in characters to use for the field being printed, where by default, blanks are added to the left of the field. width never forces a field to be truncated. width is specified by a positive number, but may be an asterix (*) in which case an int integer should appear in the argument list to specify the value required.

precision is an integer preceeded by a ".", or alternatively an asterix (*) like the width special case where an argument supplies the value. It specifies:

Type              Meaning                           Default 
----------------- --------------------------------- -----------------------------
c                 The precision has no effect.      The character is printed.

d, i, u, o, x, X  The precision specifies the       Default precision is 1. 
                  minimum number of digits to be
                  printed. Padding on the left
                  with zeros as required.
                  The value is not truncated when
                  the number of digits exceeds
                  precision.

e, E              The precision specifies the       Default precision is 6;
                  number of digits to be printed    if precision is 0 or the period
                  after the decimal point.          appears without a number following
                  The last printed digit is         it, no decimal point is printed.
                  rounded.

f                 The precision value specifies     Default precision is 6;
                  the number of digits after the    if precision is 0 or the period
                  decimal point. If a decimal       appears without a number following
                  point appears, at least one       it, no decimal point is printed.
                  digit appears before it.
                  The value is rounded to the
                  appropriate number of digits.

g, G              The precision specifies the       Six significant digits are printed,
                  maximum number of significant     with trailing zeros truncated.
                  digits printed.

s                 The precision specifies the       Characters are printed until a null
                  maximum number of characters      terminating character is encountered.
                  to be printed. Characters in
                  excess of precision are not
                  printed.

The optional type specifiers are as follows:

h  = half, which results in a short integer being processed
hh = half half, which results in a signed character being processed
l  = long, which results in an long integer being processed
ll = long long, which results in a long long integer being processed
L  = long double, is ignored as that type is not supported in JCC.
The only required value is the type which has the following character codes:

c = prints a character, which was extended to an int parameter
d = signed decimal integer
i = signed decimal integer
o = unsigned octal integer
u = unsigned decimal integer
x = unsigned hexadecimal integer, using "abcdef"
X = unsigned hexadecimal integer, using "ABCDEF"
e = double, in the form: [-]d.ddde[+|-]ddd  (where d is a digit)
E = same as e above, except the exponent uses "E" instead
f = double, in the form: [-]ddd.ddd  (where d is a digit)
g = chooses format e if the exponent value is less than -4 or
    greater than the precision, otherwise format f is printed.
    Trailing zeros are removed and the decimal only appears when required
G = save as g above, except the exponent uses "E" instead (if required)
n = pointer to integer, is used to store the number of printed characters so far
p = pointer to void, an address is printed
s = pointer to a character string, the string is printed
% = a percent sign is printed, no argument is used

Stream I/O Routines

See Also    fopen, fprintf, fscanf, scanf, sprintf, vprintf