473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

printing nice table

Hello again!

I'm struggling with adjustment of print out table :)
I would like to have some thing like this execpt with right ajustment:

var1 some_var v next_var
_________________________________________
2 3 4 23.32
simple approach
#include <stdio.h>
#include <stdlib.h>

int main(void){

printf("%s\t%6s\t%6s\t%6s\n",
"var","next_var","v","more_v");
printf("%d\t%6.2f\t%6d\t%6.2f\t\n", 1333,96.00,11,0.12);
return 0;
}
/*output*/
var next_var v more_v
1333 96.00 11 0.12

dosn't work because I don't know in advance how large those variables
will by...
how would it by possible to make table for printout with fixed with
columns, and let header as well values to by right adjusted?
Thank you in advance!
Jun 11 '07 #1
2 1801
Carramba wrote:

| dosn't work because I don't know in advance how large those
| variables will by...
| how would it by possible to make table for printout with fixed with
| columns, and let header as well values to by right adjusted?

You can either use pre-determined maximum field widths or you can make
two passes through the data, where the first pass is used to determine
the required field widths and the second does the actual output using
printf()'s '*' capability.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
Jun 11 '07 #2
Morris Dovey <mr*****@iedu.comwrote:
You can either use pre-determined maximum field widths or you can make
two passes through the data, where the first pass is used to determine
the required field widths and the second does the actual output using
printf()'s '*' capability.
It might be preferable to simply build the format string as
appropriate after the first pass and dispense with the '*'
functionality:

#include <stdio.h>
#include <string.h>

int main (int argc, const char *argv[]) {
int idx, fieldw=0;
char fmt[64]; /* Should dynamically allocate of course, but 64 is
enough here */
for( idx=1; idx < argc; idx++ ) {
if( strlen(argv[idx]) fieldw ) {
fieldw=strlen( argv[idx] ); /* Could optimize and remove duplicate
strlen call() */
}
}
sprintf( fmt, "%%%ds\n", fieldw );
for( idx=1; idx < argc; idx++ ) {
printf( fmt, argv[idx] );
}
return 0;
}

(After some thought, maybe this isn't preferable, but it's an option.)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jun 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
0
by: luca | last post by:
Hallo, here is my big problem. I will soon realease a piece of software so I wrote some documentation. I needed an HTML page that worked OK on most browsers, so I came up with this: ...
5
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am...
6
by: Les Juby | last post by:
I'm trying to print a simple catalogue of products but where an image straddles a page break, the image either disappears completely or else the first half prints at the bottom of the page but the...
1
by: G.Esmeijer | last post by:
Friends, I'm (a bit) dissapointed about the printing possibilities in c#. It could also be lack of knowedge. I would like to align a text on the right side of the paper when printing. For...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
4
by: Lucas Ponzo | last post by:
Hi All, I have an ASP.NET 2.0 app. The users access the pages, uniquely via pocket pc ... I need to print a page. But I need that the page print on a printer installed on the web server...
4
by: mark | last post by:
Ive created a aspx form using tables and flowlayout, I've set the background colour on certain rows, which show great in the browser, however when i use print preview the colours have...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
33
by: christophertidy | last post by:
Hi I am new to Python and have recieved this error message when trying to instantiate an object from a class from another file within the same directory and wondered what I have done wrong. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.