Page 1 of 1

How to add spaces in a string using C++

Posted: Wed Dec 09, 2009 3:30 am
by Neo
Pad an empty string ("") with k spaces(10 spaces)

Code: Select all

int k = 10;
char *s1 = "ROBOT.LK";
char *s2 = "Laboratories";
printf("%s%*s%s\n",s1,k,"",s2);
This will print:

Code: Select all

ROBOT.LK          Laboratories