blank spaces...

N

Nimmy

Hi,

How can I print blank spaces with printf()

I want something like printf("%6d %2d", lcVar1, lcVarb);

Printout should be:
123123 34
12 spaces in between 123123 and 34 and 15 spaces at the end again,

Thanks
 
K

Kenneth Brody

Nimmy said:
Hi,

How can I print blank spaces with printf()

I want something like printf("%6d %2d", lcVar1, lcVarb);

Printout should be:
123123 34
12 spaces in between 123123 and 34 and 15 spaces at the end again,

The most obvious is to include the spaces in the format:

printf("%6d %2d ",lcVar1,lcVarb);

Another way would be to print formatted strings between them. Note: this
is from memory, and I'm not 100% certain that this is the correct syntax.
I'm sure that someone will correct me if I'm wrong. :)

printf("%6d%.12s%2d%.15s",lcVar1,"",lcVarb,"");
 
M

Martin Ambuhl

Nimmy said:
Hi,

How can I print blank spaces with printf()

I want something like printf("%6d %2d", lcVar1, lcVarb);

Printout should be:
123123 34
12 spaces in between 123123 and 34 and 15 spaces at the end again,

#include <stdio.h>

int main(void)
{
int Var1 = 123123, Varb = 34;
printf("%6d%12s%2d%15s\n", Var1, "", Varb, "");
printf("%6d%14d%15s\n", Var1, Varb, "");
return 0;
}

[output]
123123 34
123123 34
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top