Format specification modifiers
Each format specification begins with a %
and ends with a character that determines the conversion, known as format control letter
. In between, it may contain optional modifiers that control how much of the item's value is printed or how much of total space it gets.The following are the possible modifiers that may appear in a printf
format specifier.
Printing with fixed column width
To create a fixed-column-width report, we have to specify a number immediately after the %
in the format specifier. This number shows the minimum number of characters to be printed.This is the width (minimum size) of the field.If the input in the field becomes large, it automatically grows to prevent information loss.If the input string is smaller than the specified number, spaces are added to the left.
The following example displays the basic use of printf
with fixed column width using the number specified immediately after the %
.We have added headers inside the BEGIN
statement to...