From: Ben Pfaff Date: Sun, 29 Aug 2004 22:11:32 +0000 (+0000) Subject: Fix grouping (sigh). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a97142be6bab12f56bb044a4e2b9c96854800771;p=pintos-anon Fix grouping (sigh). --- diff --git a/src/lib/lib.c b/src/lib/lib.c index 42ca2fd..17b0a80 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -369,7 +369,7 @@ printf_integer (uintmax_t value, bool negative, const char *digits, char buf[64], *cp; int base; const char *base_name; - int pad_cnt; + int pad_cnt, group_cnt; base = strlen (digits); @@ -378,10 +378,14 @@ printf_integer (uintmax_t value, bool negative, const char *digits, will output the buffer's content in reverse. This is also the reason that later we append zeros and the sign. */ cp = buf; + group_cnt = 0; while (value > 0) { - if ((c->flags & GROUP) && cp > buf && (cp - buf) % 3 == 0) - *cp++ = ','; + if ((c->flags & GROUP) && group_cnt++ == 3) + { + *cp++ = ','; + group_cnt = 0; + } *cp++ = digits[value % base]; value /= base; }