blank spaces...

Discussion in 'C Programming' started by Nimmy, Jul 5, 2004.

  1. Nimmy

    Nimmy Guest

    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
     
    Nimmy, Jul 5, 2004
    #1
    1. Advertisements

  2. 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,"");
     
    Kenneth Brody, Jul 5, 2004
    #2
    1. Advertisements

  3. #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
     
    Martin Ambuhl, Jul 5, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.