/* Legible -- return a static pointer to the legibly printed long. */ char * legible (long l) { char inbuf[24]; /* Print the number into the buffer. */ long_to_string (inbuf, l); return legible_1 (inbuf); }
/* Legible -- return a static pointer to the legibly printed long. */ char * legible (long l) { static char outbuf[20]; char inbuf[20]; int i, i1, mod; char *outptr, *inptr; /* Print the number into the buffer. */ long_to_string (inbuf, l); /* Reset the pointers. */ outptr = outbuf; inptr = inbuf; /* If the number is negative, shift the pointers. */ if (*inptr == '-') { *outptr++ = '-'; ++inptr; } /* How many digits before the first separator? */ mod = strlen (inptr) % 3; /* Insert them. */ for (i = 0; i < mod; i++) *outptr++ = inptr[i]; /* Now insert the rest of them, putting separator before every third digit. */ for (i1 = i, i = 0; inptr[i1]; i++, i1++) { if (i % 3 == 0 && i1 != 0) *outptr++ = ','; *outptr++ = inptr[i1]; } /* Zero-terminate the string. */ *outptr = '\0'; return outbuf; }