Re: was Exp Tester Program- Snippet?

From: Akuma/Chris Baggett/DOOMer (doomer@BAYOU.COM)
Date: 07/11/97


>
>sprintf(buf_temp1,"%s",cur->cl_players[0]);
>str_add_spaces(buf_temp1,12);
>sprintf(buf_temp2,"%s",cur->cl_name);
>str_add_spaces(buf_temp2,13);
>sprintf(buf_temp3,"%d",cur->cl_room);
>str_add_spaces(buf_temp3,9);
>sprintf(buf_temp4,"%d",cur->cl_number);
>str_add_spaces(buf_temp4,12);
>sprintf (send,"| %s| %s| %s| %s|\n\r",buf_temp1,buf_temp2,buf_temp3,buf_temp4);
>send_to_char(send,ch);

  well you could easily cut this down to
sprintf(send, "| %-12.12s| %-13.13s| %-9.9d| %-12.12d|\n\r",
             cur->cl_players[0], cur->cl_name, cur->cl_room, cur->cl_number);

for %d a  - in it means force it right-padded with spaces (if too short)
          and the .9 will truncate it to 9 chars if it's too long.
for %s it works basically the same way, except that in a
        %-12.12s   it'll print up 12 chars
(- means right-padded <force left-align>) and anything over 12
will just overrun, now the .12 takes care of the truncation,
I got this info from an old  Turbo C 1.0 Reference Manual that I still
use as reference, even though I don't use Turbo C to program :-) nice, eh?
---------------------------------------------------------------------------
---- NEWBIES, and people with questions about (s)printf()'s %% codes ------
---- SNIP and save (print out?) for future reference!!!    ----------------
----- everyone else, just ignore it, and don't bitch at me-----------------
----- it's good info for everyone to know ---------------------------------
---------------------------------------------------------------------------
Anyway, what follows is the rest of the % codes for printf()
I have sent them in before,  but i got a few ppl telling me there's no
use in sending em out, but they were wrong :-)

anyway, here goes

%-n.nd :    - means left-align, pad on right with spaces
        the first 'n' is the length that you will pad with spaces
               (if n=12 and stringlen = 10 then it will pad
                with 2 spaces, anything longer overruns)
         the second 'n' (after the '.') is for truncation at a certain length

%-n.ns :    - means left-align, pad on right with spaces
         the first 'n' is the length that to pad with spaces if too short
         the second 'n' is the length to truncate if too long

I could post the rest of it, but that would be spam for the list,

If anyone would like a FULL list of
(including Hex, Octal, and Floating point) Sprintf codes
just send me a direct mail, and i'll be happy to oblige,
(of course you may not get a reply for a day or so, because i work
nights.

Anyway, I hope this helped, laters and have fun coding!

Akuma the Raging Coder

  +------------------------------------------------------------+
  | "The poets talk about love, but what I talk about is DOOM, |
  |      because in the end, DOOM is all that counts." -       |
  |   Alex Machine/George Stark/Stephen King, The Dark Half    |
  |        "Nothing is IMPOSSIBLE, Just IMPROBABLE"            |
  |   "Easier Said Than Done, But Better Done Than Said..."    |
  +------------------------------------------------------------+


      +-----------------------------------------------------------+
      | Ensure that you have read the CircleMUD Mailing List FAQ: |
      |   http://cspo.queensu.ca/~fletcher/Circle/list-faq.html   |
      +-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST