Formatted Printing
printf and sprintf format a list of values according to a format string that may use the following conversions:
| A percent sign. |
| An unsigned integer (binary). |
| The character corresponding to the ordinal value. |
| A signed integer. |
| A floating-point number (scientific notation). |
| A floating-point number (fixed decimal notation). |
| A floating-point number |
| A synonym for |
| The number of characters formatted so far is stored into the corresponding variable in the parameter list. |
| An unsigned integer (octal). |
| A pointer (address in hexadecimal). |
| A string. |
| An unsigned integer (decimal). |
| An unsigned integer (hexadecimal). |
| Like |
| An obsolete synonym for |
| Like |
| An obsolete synonym for |
| Like |
| An obsolete synonym for |
| An obsolete synonym for |
| Like |
The following flags can be put between the % and the conversion letter:
space | Prefix a positive number with a space. |
| Prefix a positive number with a plus sign. |
| Left-align within the field. |
| Use zeros instead of spaces to right-align. |
| With |
number | Minimum field width. |
| For a floating-point number, the number of digits after the decimal point. For a string, the maximum length. For an integer, the minimum width. The integer will be right-aligned, padded with zeros. |
| Interpret integer as C type ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access