From a97142be6bab12f56bb044a4e2b9c96854800771 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 29 Aug 2004 22:11:32 +0000 Subject: [PATCH] Fix grouping (sigh). --- src/lib/lib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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; } -- 2.30.2