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

后端 未结 6 1647
一个人的身影
一个人的身影 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 06:00

    printf allows formatting with width specifiers. e.g.

    
    printf( "%-30s %s\n", "Starting initialization...", "Ok." );
    

    You would use a negative width specifier to indicate left-justification because the default is to use right-justification.

提交回复
热议问题