Re: [CODE]Formatting numbers with commas

From: Juliano Ravasi Ferraz (jferraz@linkway.com.br)
Date: 01/22/01


Peter Ajamian wrote:
>
> I recently wrote this little function that I use to format integers with
> commas when displaying them, I thought that someone here might benefit
> from it.
>
> (...)

I don't want to "throw cold water on you", but this is not necessary if
using glibc. You need only to set locale with setlocale(), and use "'"
(apostrophe) on format string, like as follows:

#include <locale.h>

setlocale(LC_NUMERIC, "en_US");
printf("%'d", number);

You need to setlocale() only once, probably the better place is on
main() or init_game(). I recomend to parse it's return value to check if
it was set the locale successfully.

Look at libc info to check if your glibc version supports this:

info libc "Integer Conversions"

For more information about using setlocale(), try:

info libc "Setting the Locale"

If your glibc does not support the "'" format, I suggest you to update
it to, at least, version 2.2. Many security bugs was found on previous
versions.

NOTE THAT many versions of gcc generates warnings when using "'" format
on *printf() functions, but you can safely ignore them, or use
-Wno-format option on gcc.

/* as stated on Q4 of list faq*/
static char *ObCircle = "
I'm thinking to implement a DNA-like race system to my mud. Many of the
player's characterists will be defined by two binary arrays where each
bit will represent a gene (1 = dominant, 0 = recessive). A map of the
arrays will be necessary, like that (using a char[n] array):

char[0] >> 0 -> pc has a tail    (aa = tail, A[aA] = no tail)
char[0] >> 1 -> pc has big ears  (aa = small, Aa = medium, AA = big)
char[0] >> 2 -> body hair        (aa = normal, Aa = increased, AA =
monkey-like)
...

Then, the mud will set a character's phenotic according to their genes.
Ex: It will only be able to wear ITEM_WEAR_TAIL items if its genes for
tail is Aa or AA.

On character's creation routines, there will be some pre-defined
\"pure\" races, each one with one (or many, used randomly) pair of these
gene arrays (let's call them \"cromossomes\"). The player will choose
it's parents races, and the mud will mix the cromossomes and stores it's
new cromossome in the playerfile.

Obviously, all this process will be hidden to the player (my mud has
medieval theme).

At the moment, I have nothing but the idea to this implementation. I
hope this can encourage other imps to find a new (and interesting) way
to (at least try) implement race system to their muds.
";

Hugs.
Juliano

--
----=[ Juliano Ravasi Ferraz ]=----=[ jferraz@linkway.com.br ]=----
     Rayon Eletrônica e Informática Ltda. - Linkway Descalvado

Dislexics of the world, UNTIE!

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST