September 1998
Intermediate to advanced
848 pages
20h 13m
English
Specifying fixed field widths is useful when you want to print columns of data. Because the default field width is just the width of the number, the repeated use of, say,
printf("%d %d %d\n", val1, val2, val3);
12 234 1222 4 5 23 22334 2322 10001
(This assumes that the value of the variables has been changed between print statements.)
The output can be cleaned up by using a sufficiently large fixed field width. For example, using
printf("%9d %9d %9d\n", val1, val2, val3);
12 234 1222
4 5 23
22334 2322 10001
Leaving a blank between one conversion specification and the next ensures that one number ...
Read now
Unlock full access