6 // http://c-faq.com/stdio/commaprint.html
7 char *commaprint(unsigned long n
)
9 static int comma
= '\0';
10 static char retbuf
[4*(sizeof(unsigned long)*CHAR_BIT
+2)/3/3+1]; // size=30
11 char *p
= &retbuf
[sizeof(retbuf
)-1];
15 struct lconv
*lcp
= localeconv();
17 if(lcp
->thousands_sep
!= NULL
&&
18 *lcp
->thousands_sep
!= '\0')
19 comma
= *lcp
->thousands_sep
;
27 if(i
%3 == 0 && i
!= 0)
35 char *pret
= malloc(&retbuf
[sizeof(retbuf
)]-p
); // well, just a tiny leak ...
36 return strcpy(pret
,p
);