![]() |
| | #1 |
| Registered User Join Date: Feb 2005
Posts: 11
| Formatting output into even columns? Code: host.domain.com 12.12.12.12 host123.domain.com 123.123.123.123 h.domain.com 21.21.21.21 blah.domain2.com 32.32.32.32 aaa.domain.com 111.111.111.111 while it displays the right information, the output of the program as you can see is uneven and looks generally sloppy. What I'd like to do is have it's output look more like: Code: host.domain.com 12.12.12.12 host123.domain.com 123.123.123.123 h.domain.com 21.21.21.21 blah.domain2.com 32.32.32.32 aaa.domain.com 111.111.111.111 ? Thanks.--EDIT--: In the example of how I want the output to look it still came out uneven, I guess thanks to how the forum parses my thread. Trust me though, the first number in the first octect of each IP in my example all line up >_< Last edited by Uncle Rico; 08-16-2005 at 04:31 PM. |
| Uncle Rico is offline | |
| | #2 |
| Just Lurking Join Date: Oct 2002
Posts: 4,990
| There are width specifiers for printf. Code: #include <stdio.h>
int main(void)
{
static const struct
{
const char *host, *ip;
} text[] =
{
{"host.domain.com", "12.12.12.12"},
{"host123.domain.com", "123.123.123.123"},
{"h.domain.com", "21.21.21.21"},
{"blah.domain2.com", "32.32.32.32"},
{"aaa.domain.com", "111.111.111.111"},
};
size_t i;
for ( i = 0; i < sizeof text / sizeof *text; ++i )
{
printf("%-64s %s\n", text[i].host, text[i].ip);
}
return 0;
}
/* my output
host.domain.com 12.12.12.12
host123.domain.com 123.123.123.123
h.domain.com 21.21.21.21
blah.domain2.com 32.32.32.32
aaa.domain.com 111.111.111.111
*/
__________________ 7. It is easier to write an incorrect program than understand a correct one. 40. There are two ways to write error-free programs; only the third one works.* |
| Dave_Sinkula is offline | |
| | #3 |
| Registered User Join Date: Feb 2005
Posts: 11
| Perfect! That's exactly what I needed, thanks |
| Uncle Rico is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| formatting output | kisiellll | C Programming | 2 | 04-04-2009 03:53 PM |
| Help for my output array | qwertysingh | C Programming | 1 | 02-17-2009 03:08 PM |
| Output Columns form a file | Cdrwolfe | Tech Board | 2 | 03-22-2006 05:12 AM |
| Base converter libary | cdonlan | C++ Programming | 22 | 05-15-2005 01:11 AM |
| formatting output | spliff | C Programming | 2 | 08-14-2001 06:50 PM |