Professional Web Applications Themes

How to make nice columns? - Mac Programming

Hi, I am working on a command line tool which outputs data in the form of columns (5 to 9 columns, and many lines). I use the fprintf() command to put the data onscreen, but as every entry has a different size, it makes the table ugly, and very hard to read! It there a good way to format the output to have nice columns? Thanks in advance, -- Arthur...

  1. #1

    Default How to make nice columns?

    Hi,

    I am working on a command line tool which outputs data in the form of
    columns (5 to 9 columns, and many lines).
    I use the fprintf() command to put the data onscreen, but as every
    entry has a different size, it makes the table ugly, and very hard to
    read! It there a good way to format the output to have nice columns?

    Thanks in advance,

    -- Arthur
    Arthur Guest

  2. #2

    Default Re: How to make nice columns?

    In article <local>,
    Arthur VIGAN <fr> wrote:
     

    All variants of printf allow use of fields to be fixed. For instance,
    printf("%6d", interger_number); will always print 6 characters (if the
    number is smaller, than spaces are added on the left so that the last
    digit always appear on the same column.

    Patrick
    --
    Patrick Stadelmann <ch>
    Patrick Guest

  3. #3

    Default Re: How to make nice columns?

    Arthur VIGAN wrote: 
    If you are writing to stdout, perhaps printf() might be sufficient ?
     
    There are many formatting options to the printf() family.
    They will be closely dependant on the type and length of your data.

    You can specify for instance a maximum length, left or right
    alignment, the type of the data.

    The maximum length with padding option can be considered as some kind
    of tabbing and might do what you're looking for.

    In any case, i'm afraid there won't be any predefined solution and
    you'll have to fight with
    man 3 printf
    to forge your own format string.

    Don't forget that a * in place of the field width or precision means
    that the corresponding argument gives the value : this lets you have
    computed length.

    HTH

    --
    Olivier
    This space for sale.

    oliv Guest

Similar Threads

  1. Datagrid - Make columns match XML order
    By frbtrain in forum Macromedia Flash Data Integration
    Replies: 3
    Last Post: July 13th, 09:43 AM
  2. how to make columns the same size in a radio button list
    By Trevor Hartman in forum ASP.NET General
    Replies: 1
    Last Post: August 1st, 05:55 PM
  3. how to return ds, w/ XSL to make it look nice for non-.NET user?
    By Jason Shohet in forum ASP.NET Web Services
    Replies: 0
    Last Post: August 1st, 02:54 PM
  4. Replies: 0
    Last Post: July 2nd, 06:18 AM
  5. Replies: 3
    Last Post: January 13th, 07:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139