Skip to contentSkip to conversation

Inserting Commas into Those Big Numbers

DISCUSSION Jeff V. Merkey 2 participants 2 messages Jan 19, 2006 – Jan 20, 2006

lore
Share & tools
lore
#0 lore raw

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] = ',';
	   }
	}
     }
}
#1 lore raw
Quoted 4 lines · Jeff V. Merkey

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.

you know i wish C99 had mandated support for numbers like 1_000_000 or 0x0123_4567_89ab_cdef. (not sure if Ada originated this style, but that's where i first saw it.)

-dean