Inserting Commas into Those Big Numbers

From: Jeff V. Merkey
Date: Thu Jan 19 2006 - 01:45:17 EST



If anyone cares to make the kernel output more readable, heres a code snippet that formats any text string with numbers (decimal) to
insert commas. I am too old and going blind looking at computer screen with these long numbers. If useful to anyone, enjoy.

Jeff



void sprintf_comma(char *buf, char *fmt, ...)
{

register long i, r, flag, len;
va_list args;

va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);

for (len = i = strlen(buf), flag = 0; i >= 0; i--)
{
if (buf[i] >= '0' && buf[i] <= '9')
{
if (++flag > 3)
{
flag = 1;
for (r = ++len; r > i; r--)
buf[r] = buf[r - 1];
buf[i + 1] = ',';
}
}
}
}