How to repeat a char using printf?

Muis picture Muis · Feb 4, 2013 · Viewed 156.1k times · Source

I'd like to do something like printf("?", count, char) to repeat a character count times.

What is the right format-string to accomplish this?

EDIT: Yes, it is obvious that I could call printf() in a loop, but that is just what I wanted to avoid.

Answer

rep_movsd picture rep_movsd · Apr 30, 2013

You can use the following technique:

printf("%.*s", 5, "=================");

This will print "=====" It works for me on Visual Studio, no reason it shouldn't work on all C compilers.