Increase in digits = removal of space

Posted by Asean Novari on Thu 04 Nov 2004 06:55 PM — 7 posts, 26,397 views.

USA #0
Ok.. i am running the SWR 1 Fuss that i got from this site..
Its running on windows, compiled with cygwin..

I was wondering if there is a way to code in something that
will remove a "space" character from a line whenever one of
the values in that like gets one digit bigger and likewise
add a "space" when the number gets smaller

Spacecraft/Vehicles/Members/Funds
93         75       387     10983 <-- This is how i want it
93          75        387       10983 <-- This is how it is

I know i can make it the way i want it by manually going in an
and removing a space.. but i would like it to keep my general
form without me having to tamper with it every time the number
gets another digit added ot removed from it..

I searched the forums for a topic that covered this but could
not find any. If this is a repeat topic please accept my
apologies and bear with me or refer a link to the older topic

Any help would be greatly appreciated.. Thanks
Amended on Thu 04 Nov 2004 07:50 PM by Asean Novari
Canada #1
What you can do is check the man page for sprintf ( I think ), this will give you instructions on how to use printf formating, to assign a definite amount of space that a number will take up, so that regardless of how many numbers(79 or 123), it will format them out to always show 10 characters wide
USA #2
Couldn't find what you were talking about.. i even did a
search on sprintf and looked over all the posts.. whatever i
found in them i didnt understand.. an elaboration would be
appreciated..
USA #3
Yeah, it's in the man page for sprintf.

   Format of the format string

Under that section of the manual.
Canada #4
What you need is something like this:
ch_printf(ch, "%10d %10d %10d %10d\n\r" ships, vehicles, clan->members, clan->funsd);
Something like that, I'm at work, but if you still can't figure it out, I will give you an exact example out of stock SWR in a few hours from this post.

The man page will give you how and why this works, though I am terrible with sprintf from memory, so I may be incorrect, but it should be close to that. You can change the 10 to however many spaces you want it to take up.
Amended on Fri 05 Nov 2004 01:26 AM by Greven
Canada #5
Actually, looking at the stock code in do_clans, this is what shows up:
        ch_printf( ch, "  &WDivision             Leaders             Spacecraft/Vehicles/Members/Funds\n\r");
        ch_printf( ch, "  &O%-20s %-10s %-10s %-10s %-2d %-2d %-3d %ld\n\r",
                  "Main", clan->leader, clan->number1, clan->number2, clan->spacecraft, clan->vehicles, clan->members, clan->funds );
 The only issue that I can see is that the leaders, number1, and number2, when only 20 spaces are included.
Australia Forum Administrator #6
The %-2d needs to be bigger, eg. %-3d.

That is allowing for a 2-digit number. The - changes from left to right justification, or vice-versa.