#include <stdio.h>
#include <string.h>
int main(void) {
long n = 84940083567;
char commas_number[64];
sprintf(commas_number, "%ld", n);
int length = strlen(commas_number);
int commas = ( length - 1 ) / 3;
char *p = &commas_number[length];
char *commasp = commas_number + length + commas;
*commasp-- = *p--;
for (int i = 1; p >= commas_number; i++) {
*commasp-- = *p--;
if ( ( i % 3 ) == 0 )
*commasp-- = ',';
}
puts(commas_number);
return 0;
}
/*
run:
84,940,083,567
*/