Aligning strings display format

This is a discussion on Aligning strings display format within the C Programming forums, part of the General Programming Boards category; I know I can use the %20s to reserve 20spaces and print out the string from the left, but how ...

  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,796
    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,161
    I posted a program at the end of thread formatted output
    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, 01:53 AM
  4. How to display integer to binary format?
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 12:32 AM
  5. Table mapping Strings to Strings
    By johnmcg in forum C Programming
    Replies: 4
    Last Post: 09-05-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21