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
➜ character spacing smaug/swr
|
character spacing smaug/swr
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Thu 08 Feb 2007 06:41 PM (UTC) Amended on Thu 08 Feb 2007 06:51 PM (UTC) by Jason
|
| Message
| ok here is my question.
On swr while coding you can put in something like this:
ch_printf(ch, "|Name: %5s|&\n\r", ch->name,
where %5s makes a spacing of 5 characters. now lets say a persons name is bobbie. it will add the 6th character space automaticly and throw off my ANSI picture i was trying to create... is there a way to cut off the input early so that it doesn't add the extra characters so it looks like this:
+-----------+
|Name: bobbi|
+-----------+
instead of this:
+-----------+
|Name: bobbie|
+-----------+
| | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #1 on Thu 08 Feb 2007 07:08 PM (UTC) |
| Message
|
char buf[6];
ch_printf(ch, "|Name: ");
snprintf(buf, 6, "%5s", ch->name);
ch_printf(ch, "%s|&\n\r", buf);
You can (and of course should) reuse the 'buf' variable for every player.
As an editorial comment, only 5 characters for player names is a little short. I'd go for something like 8 or 9. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #2 on Thu 08 Feb 2007 07:12 PM (UTC) |
| Message
| | actual spacing is 20.... put i need the info for other spots in my code... this was just a for instance | | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #3 on Thu 08 Feb 2007 07:14 PM (UTC) |
| Message
| and i need to know if there is away to do it in one line
cause finished progect looks like this:
+--------+-----------+---------------+---------------------------+---------------------------------+
|AGE: 229|ALIGN:-920 |ARMOR:-392 |NAME: Koumintang |CREDITS:536690 |
+--------+-----+-----+--------+------+----------+----------------+---------------------------------+
| | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #4 on Thu 08 Feb 2007 07:15 PM (UTC) |
| Message
| like with age.... if it gets over 999 and moves to 1000 then it will move the whole rest the line over one
| | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #5 on Thu 08 Feb 2007 07:20 PM (UTC) |
| Message
| Just do what I did, but multiple times. Don't print out the newline until you want to.
The point of the snprintf function is to print only so-many characters into the buffer (the number includes the \0, so 6 really means 5 characters).
See man snprintf for more information. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #6 on Thu 08 Feb 2007 07:33 PM (UTC) |
| Message
| k i'll give it a shot
| | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #7 on Thu 08 Feb 2007 07:38 PM (UTC) |
| Message
| | now the different spaces needs different maxes will that matter? | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #8 on Thu 08 Feb 2007 07:41 PM (UTC) |
| Message
| Of course, you'll need to use different sizes for snprintf.
If I may make a suggestion you should slow down a little and understand why what I posted does what you want. The questions you're asking indicate to me that you don't really know what the code I posted does, because your questions have very easy answers. Sometimes, taking the time to slow down will let you go much faster in the future. :-) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #9 on Thu 08 Feb 2007 07:42 PM (UTC) |
| Message
| | Read up on the printf function. You can use "*" in the string to indicate that the width is a variable amount - that is, you supply the width itself as an argument. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #10 on Thu 08 Feb 2007 07:43 PM (UTC) |
| Message
|
Quote:
if it gets over 999 and moves to 1000 then it will move the whole rest the line over one
Do you really want to truncate the age? If you do, and someone has age 1020, then it will show as 20, is that really what you want? Isn't that misleading? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #11 on Thu 08 Feb 2007 07:46 PM (UTC) |
| Message
| I think he wants to truncate the length of the string to e.g. 3, not the actual number. So in his case, 102 would appear as 102 -- which still isn't what he wants (well, maybe it is).
Jason, if you want to truncate numbers you will have to determine what the max is, and if it's above the max just print the max (e.g. 999) and otherwise print the normal value. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #12 on Thu 08 Feb 2007 07:54 PM (UTC) Amended on Thu 08 Feb 2007 07:56 PM (UTC) by Jason
|
| Message
| ok lets try this again
+--------+-----------+---------------+---------------------------+---------------------------------+
|AGE: 229|ALIGN:-920 |ARMOR:-392 |NAME: Koumintang |CREDITS:536690 |
+--------+-----+-----+--------+------+----------+----------------+---------------------------------+
ignore age all together
we will use the name field
it is 20 characters long
if a person's name is longer than 20 characters
it will strech out that spacing... instead of it streching it out i want it to just cut it off
example
this is what it does now
+--------+-----------+---------------+---------------------------+---------------------------------+
|AGE: 229|ALIGN:-920 |ARMOR:-392 |NAME: thisislongerthan20characters |CREDITS:536690 |
+--------+-----+-----+--------+------+----------+----------------+---------------------------------+
this is what i want it to do
+--------+-----------+---------------+---------------------------+---------------------------------+
|AGE: 229|ALIGN:-920 |ARMOR:-392 |NAME: thisislongerthan20ch |CREDITS:536690 |
+--------+-----+-----+--------+------+----------+----------------+---------------------------------+
i want it to just cut it off and not move everything after it | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #13 on Thu 08 Feb 2007 07:58 PM (UTC) |
| Message
| | I already told you how to do that. I'm not sure why you are repeating the question; did the answer not work? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Jason
(109 posts) Bio
|
| Date
| Reply #14 on Thu 08 Feb 2007 09:16 PM (UTC) |
| Message
| Ok the reason i reposted was so that nick knew what i was talking about... cause in his post he was still wondering. and the reasoni was asking the questions was so i could understand it better.. And thanx for the help... i did get it to work after a little fiddling with it
works perfectly thanx again
| | 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.
56,877 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top