user1701840
user1701840

Reputation: 1112

How to have absolute padding in printf()?

I tried

printf("%s %15s", string1, string2);

and I found out that this kind of left padding depends the distance from the first string, what if I want an absolute left padding counting from the left most?

Upvotes: 1

Views: 314

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64308

You want to pad the first string on the right, instead of padding the second sting on the left:

printf("%-15s %s",string1,string2);

Upvotes: 8

Related Questions