Thread: Aligning strings display format

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Aligning strings display format

    I know I can use the %20s to reserve 20spaces and print out the string from the left, but how can I do it to reseve the spaces and start filling from the right.
    This is how the output is looking
    Code:
    Name                 Regular_Pay Overtime_Pay Gross_Pay  Tax_Deducted   Net_Pay
                       h      437.50         0.00    437.50        109.38    328.12
             Mayr Silver      480.00         0.00    480.00        120.00    360.00
           jennifer kahn      540.00       212.62    752.62        188.16    564.47
               jacjjg gg      500.00         0.00    500.00        125.00    375.00
    jjjjjj jnhroknr popo      400.00       450.00    850.00        212.50    637.50
    jjjjjj jnhroknr popf      400.00       450.00    850.00        212.50    637.50
    I'm using this to print:
    Code:
    printf ("%20s %11.2f  %11.2f%10.2f %13.2f% 10.2f\n", name, reg_pay, overtm_pay, gross_pay, tax_deduct, net_pay);

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You can left justify with %-20s.
    My best code is written with the delete key.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    I posted a program at the end of thread http://cboard.cprogramming.com/showt...ing+and+format
    to display various formats. It will help you with this and other string formats
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My text doesn't display
    By joeprogrammer in forum Game Programming
    Replies: 11
    Last Post: 02-23-2006, 10:01 PM
  2. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  3. display file objects in different format
    By vijay_bhullar in forum C Programming
    Replies: 7
    Last Post: 09-25-2005, 12:53 AM
  4. How to display integer to binary format?
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2005, 11:32 PM
  5. Table mapping Strings to Strings
    By johnmcg in forum C Programming
    Replies: 4
    Last Post: 09-05-2003, 11:04 AM