blank spaces...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nimmy

    #1

    blank spaces...

    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



  • Kenneth Brody

    #2
    Re: blank spaces...

    Nimmy wrote:[color=blue]
    >
    > 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,[/color]

    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%.12 s%2d%.15s",lcVa r1,"",lcVarb,"" );

    --
    +-------------------------+--------------------+-----------------------------+
    | Kenneth J. Brody | www.hvcomputer.com | |
    | kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
    +-------------------------+--------------------+-----------------------------+

    Comment

    • Martin Ambuhl

      #3
      Re: blank spaces...

      Nimmy wrote:
      [color=blue]
      > 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,[/color]

      #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

      Comment

      Working...