Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Increase in digits = removal of space

Increase in digits = removal of space

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Asean Novari   USA  (82 posts)  Bio
Date Thu 04 Nov 2004 06:55 PM (UTC)

Amended on Thu 04 Nov 2004 07:50 PM (UTC) by Asean Novari

Message
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



Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #1 on Thu 04 Nov 2004 09:14 PM (UTC)
Message
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

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Asean Novari   USA  (82 posts)  Bio
Date Reply #2 on Fri 05 Nov 2004 12:37 AM (UTC)
Message
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..



Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #3 on Fri 05 Nov 2004 12:45 AM (UTC)
Message
Yeah, it's in the man page for sprintf.

   Format of the format string

Under that section of the manual.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #4 on Fri 05 Nov 2004 01:23 AM (UTC)

Amended on Fri 05 Nov 2004 01:26 AM (UTC) by Greven

Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #5 on Fri 05 Nov 2004 03:39 AM (UTC)
Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #6 on Sat 06 Nov 2004 08:19 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,634 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.