linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Inserting Commas into Those Big Numbers
@ 2006-01-19  4:59 Jeff V. Merkey
  2006-01-20  2:03 ` dean gaudet
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff V. Merkey @ 2006-01-19  4:59 UTC (permalink / raw)
  To: Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 270 bytes --]


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



[-- Attachment #2: sprintf_comma.c --]
[-- Type: text/x-csrc, Size: 432 bytes --]


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] = ',';
	   }
	}
     }
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Inserting Commas into Those Big Numbers
  2006-01-19  4:59 Inserting Commas into Those Big Numbers Jeff V. Merkey
@ 2006-01-20  2:03 ` dean gaudet
  0 siblings, 0 replies; 2+ messages in thread
From: dean gaudet @ 2006-01-20  2:03 UTC (permalink / raw)
  To: Jeff V. Merkey; +Cc: Linux Kernel Mailing List

On Wed, 18 Jan 2006, Jeff V. Merkey wrote:

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-20  2:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-19  4:59 Inserting Commas into Those Big Numbers Jeff V. Merkey
2006-01-20  2:03 ` dean gaudet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).