Crossware

Table of Contents        Previous topic       Next topic       

C COMPILER LIBRARY FUNCTION REFERENCE->Detailed Descriptions->printf()

Summary

#include <stdio.h>

int printf(const char *format, ...);


Parameters

    
formatFormat control string
...Optional arguments to be converted and printed

Description

This function converts, formats and writes its arguments to the standard output (stdout).

The format control string contains two types of objects:

- ordinary characters
- conversion specifications

Ordinary characters are simply copied to the standard output.  Conversion specifications cause the conversion and printing of the next successive argument.

A conversion specification begins with the character '%' and ends with one of the conversion characters listed below.  A number of control characters may be placed between the '%' and the conversion character as also listed below.


Control Characters:

A minus sign specifies that the argument should be left adjusted in its field.

A digit string specifying the minimum field width.  The converted argument will be printed in a field at least this wide.  If the converted argument is smaller than this field, then it will be padded on either the right or the left according to whether it is printed left or right justified.   The padding character is a space character by default or 0 if the field width was specified with a leading zero.

A period which separates the field width from the next digit string.

A digit string, the precision specification, which specifies the maximum number of characters to be printed from a string.

A length modifier h.  For integers, this indicates that the corresponding data item is short rather than an int.

A length modifier l (letter l).  For integers, this indicates that the corresponding data item is long rather than an int.

A length modifier L.  For floating point values it indicates that the corresponding data item is long double rather than float.

The printf conversion characters are:

    
CharacterArgument typeConverted to
    
d,iintsigned decimal notation
ounsigned intoctal notation (without a leading zero)
xunsigned inthexadecimal notation (without a leading 0X)
uuUnsigned intunsigned decimal notation
cintsingle character, after conversion to unsigned char
schar *characters in the string are printed until the null character is reached or until the number of characters indicated by the precision specification have been printed.
e,Edoubledecimal notation of the form [-]m.dddddE-xx (E can be lower case) where the number of d's is specified by the precision.  The default precision is 6.  A precision of 0 suppresses the decimal point.
fdoubledecimal 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.
g,Gdouble%e or %E is used if the exponent is less than -4 or greater than or equal to the precision, otherwise %f is used.

If the character following the '%' is not a conversion character, then that character is simply send to the standard output stream.  In this way it is possible to print the '%' itself with '%%'.


Return Value

The function returns the number of characters printed.