How to format strings using printf() to get equal length in the output

You can specify a width on string fields, e.g.

printf("%-20s", "initialization...");

And then whatever’s printed with that field will be blank-padded to the width you indicate.

The - left-justifies your text in that field.

Leave a Comment