View Full Version : aranging C prog output into columns

02-27-2005, 10:51 AM
hey there, i'm currently trying to produce a program and output data in the following format:


apparently i have to get the output as close to that as possible, but i don't know any other ways of printing stuff out other than just text and spaces, or using \t, but if i use either of those then whenever the length of a bane ir weight changes then the text to the right of it is gonna get unaligned.

the best way i can think of is counting the words/numbers in one bit of data (name/weight) then adding the correct number of spaces after it to line the following data up.

is there any easier way of laying stuff out like in the example?

02-27-2005, 11:39 AM
You can use formatting identifiers in printf (http://www.phim.unibe.ch/comp_doc/c_manual/C/FUNCTIONS/format.html) (check out the minimum field width). If you're using C++'s cout there is something similar for it too.


02-27-2005, 12:10 PM
thanks, that works great :thumbsup: a center align would be nice though :p