How to add spaces in a string using C++

C, C++, Visual C++, C++.Net Topics
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to add spaces in a string using C++

Post by Neo » Wed Dec 09, 2009 3:30 am

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
Post Reply

Return to “C/C++ Programming”