Skip to content
NMSnabbit.

Test Printf Online

Preview printf format strings with width, precision and flags.

Encoders & Decoders Runs in your browser

How do you test printf online?

Preview printf output without compiling a test program. The first line holds your format string; the lines after it hold the arguments. %05.2f fed 3.14159 prints 03.14, %x fed 255 prints ff, and width, precision, zero-padding and the left-align flag all behave the way C does. Backslash escapes in the format work too, so \n produces a real newline.

How to use the Test Printf Online

  1. 1 Put the format string on line one.
  2. 2 List arguments on the lines below, separated by commas or spaces.
  3. 3 Compare the rendered output against what your program should print.
  4. 4 Adjust width, precision or flags and watch the output follow.

What you can use it for

  • Checking a format string before using it in code.
  • Learning how printf flags and widths behave.
  • Teaching number formatting in lessons.
  • Debugging misaligned printf output.

Frequently asked questions

Which specifiers does the tester know?
%d, %i and %u for integers, %o, %x and %X for octal and hex, %f, %e and %g for floats, %s for strings, %c for characters and %% for a literal percent sign.
Are width, precision and flags honoured?
Yes. %8.2f right-aligns to eight characters with two decimals, %08d zero-pads, and the - flag switches to left alignment inside the field.
How do I test output that spans lines?
Write \n in the format string where a break belongs. Escape sequences are interpreted, so \t works for tab alignment as well.

Related tools

More Encoders & Decoders

More tools like this:

All Encoders & Decoders