1

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?

user1701840
  • 1,062
  • 3
  • 19
  • 27
  • It should depend on the distance from first string.What if the first string has 20 characters?Do you want second string to overlap the output of first string?It will mess things up. – Rüppell's Vulture May 13 '13 at 02:56
  • but if I have many different length of string1s, then string2s will not align correctly – user1701840 May 13 '13 at 02:59
  • 1
    It's help ? http://stackoverflow.com/questions/293438/left-pad-printf-with-spaces – Rick May 13 '13 at 03:01

1 Answers1

8

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

printf("%-15s %s",string1,string2);
Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132