How to separate numbers in three-digit groups in C
Hopelessly in love w/Donna Reed
angst at fig.ucsb.edu
Tue Jun 25 04:44:56 AEST 1991
In article <1991Jun24.134512.27162 at leland.Stanford.EDU> dkeisen at leland.Stanford.EDU (Dave Eisen) writes:
>In article <12192 at hub.ucsb.edu> angst at cs.ucsb.edu (Hopelessly in love w/Donna Reed) writes:
>>This function will work. It assumes the number is contained in a string
>>(which you can do by using sprintf()) --
>>
>
>No it won't. It bombs on -123 for example.
True, my solution doesn't work for negative numbers.
Add the following as the first line of the function:
if (s && *s == '-') {
putchar ('-');
s++;
}
-d
"Let the fools have their tartar sauce." | Dave Stein
- Mr. Burns | angst at cs.ucsb.edu
| angst%cs at ucsbuxa.bitnet
More information about the Comp.lang.c
mailing list