O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required