printf alignment

This is a discussion on printf alignment within the C Programming forums, part of the General Programming Boards category; take a look at the code snippet below: Code: printf("%d. %s\t\t%d talants\n", j, store[i].product_name, store[i].price); I want all the numbers/ints ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    printf alignment

    take a look at the code snippet below:

    Code:
    printf("%d. %s\t\t%d talants\n", j, store[i].product_name, store[i].price);
    I want all the numbers/ints before the word "talants" to be aligned in one line, I've tried to use \t\t, however it is still not aligned.. is there a way to do this?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    have you tried to use width specifier for the %s and/or %d formats (depending what is causing you the misplacement of the column)?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    how can you use the width specifier in this case?

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by -EquinoX- View Post
    how can you use the width specifier in this case?
    have you googled it?

    printf format specifications quick reference
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 08:23 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

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