adjusting output to the centre

This is a discussion on adjusting output to the centre within the C Programming forums, part of the General Programming Boards category; Is there a printf format placeholder that adjust an output to the centre?...

  1. #1
     is offline
    ex-samurai 's Avatar
    Join Date
    Nov 2006
    Location
    England
    Posts
    18

    adjusting output to the centre

    Is there a printf format placeholder that adjust an output to the centre?

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    If you know the console window is 25 characters across, so write a function to output 12 or 13 spaces. It's not the best solution, I'm sure, but it should work.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > Is there a printf format placeholder that adjust an output to the centre?
    No, because there is no good way to find out what the width is, or even if there is a width (for example output to a file).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Logical Aesthetician codepoet's Avatar
    Join Date
    Nov 2006
    Posts
    14
    you can write your own printf wrapper function, using a va list and vsnprintf, then just do something like ( console size - length of string ) / 2 to find out how much whitespace to output before your string.

    edit: Salem is correct in that there is no reliable way to grab the console size, but if you're not concerned with portability, you can manually define a constant for the size that you'll personally be using.
    Last edited by codepoet; 11-23-2006 at 10:41 AM.

  5. #5
     is offline
    ex-samurai 's Avatar
    Join Date
    Nov 2006
    Location
    England
    Posts
    18
    ok. cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 02:29 PM
  3. Replies: 4
    Last Post: 11-30-2005, 03:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM

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