lkml.org 
[lkml]   [2006]   [Jan]   [19]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateWed, 18 Jan 2006 21:59:59 -0700
From"Jeff V. Merkey" <>
SubjectInserting Commas into Those Big Numbers
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] = ',';
	   }
	}
     }
}
\
 
 \ /
  Last update: 2006-01-19 07:48    [from the cache]
©2003-2008