Inserting Commas into Those Big Numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux