Thread: printf alignment

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    have you tried to use width specifier for the %s and/or %d formats (depending what is causing you the misplacement of the column)?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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, 09:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05: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, 09: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