Thread: Formating strings

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    53

    Formating strings

    Just a quick question, how do i format my string output so that the space after the string is left blank?

    e.g

    Code:
     printf("   %5s %25s $%d.%d $%d.%d $%d.%d\n",
                   headItem->itemID, headItem->itemName,
                   headItem->prices[0].dollars, headItem->prices[0].cents,
                   headItem->prices[1].dollars, headItem->prices[1].cents,
                   headItem->prices[2].dollars, headItem->prices[2].cents);
    The text is red is the maximum length that the string could be but it pads left and not right.
    How do i make it pad right?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The manual says:
    Quote Originally Posted by man printf
    The flag characters

    The character % is followed by zero or more of the following flags:
    [snip]
    -

    The converted value is to be left adjusted on the field boundary. (The default is right justification.) Except for n conversions, the converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A - overrides a 0 if both are given.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Read the manual? Specifically, the flags entries.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    53
    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Formating Tab Control
    By iWizardPro in forum Windows Programming
    Replies: 1
    Last Post: 04-13-2010, 07:08 PM
  2. cin and formating
    By Hexxx in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2004, 01:11 PM
  3. help formating old floppies
    By kwm32 in forum Networking/Device Communication
    Replies: 9
    Last Post: 04-01-2004, 04:09 PM
  4. Need help formating Win XP
    By gqchynaboy in forum Tech Board
    Replies: 6
    Last Post: 11-13-2003, 01:42 PM
  5. Formating
    By jrahhali in forum Tech Board
    Replies: 10
    Last Post: 08-29-2003, 08:11 PM