Table of Contents
Previous topic Next topic
C COMPILER LIBRARY FUNCTION REFERENCE->Detailed Descriptions->printf()
int printf(const char *format, ...);
|format||Format control string|
|...||Optional arguments to be converted and printed|
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.
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:
|Character||Argument type||Converted to|
|d,i||int||signed decimal notation|
|o||unsigned int||octal notation (without a leading zero)|
|x||unsigned int||hexadecimal notation (without a leading 0X)|
|u||uUnsigned int||unsigned decimal notation|
|c||int||single character, after conversion to unsigned char|
|s||char *||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,E||double||decimal 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.|
|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.|
|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.|
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 '%%'.
The function returns the number of characters printed.