Advanced printf() Usage
Through most of this chapter and the book, the printf() function has been used in a rather minimal way. We have used it to print simple messages or even those with variables, thanks to special placeholders. But the function can be customized in far more ways. Just one example is using %0.1f to format a float to a single decimal point (as in the temperature-conversion examples).
Each placeholder in a printf() statement can use many formatting parameters, each of which is placed between the initial percent sign and the final signifying character (c for character, s for string, d for integer, f for float, etc.). There are basically three extra formatting options.
First, there is a flag. This can be any one of the values in ...
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