How to repeat a char using printf?

前端 未结 12 1169
难免孤独
难免孤独 2020-11-28 03:24

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

What is the right format-string to accomplish

12条回答
  •  抹茶落季
    2020-11-28 04:25

    If you limit yourself to repeating either a 0 or a space you can do:

    For spaces:

    printf("%*s", count, "");
    

    For zeros:

    printf("%0*d", count, 0);
    

提交回复
热议问题