Re: [newbie] a rather simple question..

From: Mythran (kip_potter@hotmail.com)
Date: 06/24/02


> I stumbled over this in an sprintf line.. %-20.20s, i am only familiar
with
> %s and %d and so on.. what is the -20.20 for? is it to make a space before
> or after it? could i use the same principle in my do_who command to make
it
> look nicer?
>
> eg. if i want to make these lines aligned like this
>
> Str: 18        Hp:   500/500
> Dex: 15        Mana: 500/500
>
> or is there another method i should use to make the hp and mana lines
> independent of the previous lines?
>
> /Peter
>

%-20.20s

%-20.20s means if the string is LESS THAN 20 bytes, add spaces until it is
equal to 20 bytes...the .20 portion means if the string is GREATER THAN 20
bytes, chop the remaining portion of the string....therefore, you will have
no more than 20 characters on the line, as well as no less than 20
characters.

If you wanted to align the hp and str as you noted, use the following:
sprintf(buf, "Str: %-2d        Hp:   %3d/%-3d\r\n"
             "Dex: %-2d        Mana: %3d/%-3d\r\n",
  GET_STR(ch), GET_HIT(ch), GET_MAX_HIT(ch),
  GET_DEX(ch), GET_MANA(ch), GET_MAX_MANA(ch));

Hope this helps!

Mythran


the -20 means to align to the left a minimum of 20 spaces.  The .20 means it
is a maximum of

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT