By default, printf()
seems to align strings to the right.
printf("%10s %20s %20s
", "col1", "col2", "col3");
/* col1 col2 col3 */
I can also align text to the left like this:
printf("%-10s %-20s %-20s", "col1", "col2", "col3");
Is there a quick way to center text? Or do I have to write a function that turns a string like test
into (space)(space)test(space)(space)
if the text width for that column is 8?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…