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

后端 未结 6 1652
一个人的身影
一个人的身影 2020-11-28 05:10

I have two functions, one which produces messages like Starting initialization... and another which checks return codes and outputs \"Ok\", \

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 05:56

    You can specify 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.

提交回复
热议问题