How to print 80 col name-pairs?

Discussion in 'C Programming' started by beagle197@hotmail.com, Dec 11, 2007.

  1. Guest

    Folks,

    What is a good way to print a standard 80 (or less) column of text
    where the left side being a field name text, and right side being the
    space padded value? e.g. "image_handle<space-padding>0xff". This is
    useful for outputting many lines of aligned debugging data, making it
    easier to read and track down bugs.

    I have something like this:

    /* gcc -W -Wall -o handle handle.c */
    #include <stdio.h>

    int main(void) {
    int nArray[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int *handle = &nArray[0];

    fprintf(stderr, " int_ptr 0x%x\n", (unsigned int) handle);
    return 0;
    }

    Outputs :

    int_ptr 0xbffffa70

    Seems I could use some sprintf macros that computes the length, and
    offsets with the approp number of spaces between the field value
    pairs, but I wondered if anyone has suggestions.

    Thanks,
    BEA
     
    , Dec 11, 2007
    #1
    1. Advertising

  2. said:

    > Folks,
    >
    > What is a good way to print a standard 80 (or less) column of text
    > where the left side being a field name text, and right side being the
    > space padded value?


    If I'm reading you correctly:

    printf("%30s%0x\n", "int_ptr", (unsigned int)handle);

    will display int_ptr in a 30-character-wide field. It will be
    right-justified, but using %-30s instead will left-justify it nicely for
    you.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Dec 11, 2007
    #2
    1. Advertising

  3. Guest

    Nice move, Richard, this is exactly what was needed.
    Thanks

    On Dec 11, 10:50 am, Richard Heathfield <> wrote:
    > said:
    >
    > > Folks,

    >
    > > What is a good way to print a standard 80 (or less) column of text
    > > where the left side being a field name text, and right side being the
    > > space padded value?

    >
    > If I'm reading you correctly:
    >
    > printf("%30s%0x\n", "int_ptr", (unsigned int)handle);
    >
    > will display int_ptr in a 30-character-wide field. It will be
    > right-justified, but using %-30s instead will left-justify it nicely for
    > you.
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999
     
    , Dec 13, 2007
    #3
  4. CBFalconer Guest

    wrote: *** and top-posted - fixed ***
    > Richard Heathfield <> wrote:
    >> said:
    >>
    >>> What is a good way to print a standard 80 (or less) column of
    >>> text where the left side being a field name text, and right
    >>> side being the space padded value?

    >>
    >> If I'm reading you correctly:
    >>
    >> printf("%30s%0x\n", "int_ptr", (unsigned int)handle);
    >>
    >> will display int_ptr in a 30-character-wide field. It will be
    >> right-justified, but using %-30s instead will left-justify it
    >> nicely for you.

    >
    > Nice move, Richard, this is exactly what was needed.


    Note where Richard placed his answer, and what he snipped.

    Please do not top-post. Your answer belongs after (or intermixed
    with) the quoted material to which you reply, after snipping all
    irrelevant material. I fixed this one. See the following links:

    --
    <http://www.catb.org/~esr/faqs/smart-questions.html>
    <http://www.caliburn.nl/topposting.html>
    <http://www.netmeister.org/news/learn2quote.html>
    <http://cfaj.freeshell.org/google/> (taming google)
    <http://members.fortunecity.com/nnqweb/> (newusers)



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Dec 13, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    861
    Roedy Green
    Jan 2, 2006
  2. keto
    Replies:
    0
    Views:
    1,000
  3. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    374
    David Cournapeau
    Dec 30, 2008
  4. Antonio Quinonez
    Replies:
    2
    Views:
    180
    Antonio Quinonez
    Aug 14, 2003
  5. Replies:
    8
    Views:
    216
    Eric Sosman
    Apr 20, 2013
Loading...

Share This Page