So, as far as I understood, you have a number like that: abc....afrsd...000...0000. Where abc...afrsd are figures and after that figures you have 000...00 and you want to put a comma between the figures which are different from 0 and the 0 figures. Am I right?
If so, is not so hard. You said that you have the number in a string form. This is good.
First of all, you get the length of the string with
strlen
function and then you initialize the first component after the last component of the string
your_string[strlen(your_string)+1] = '0'
with 0 as you see. Then you initialize the next component with NULL character, to finish the string:
your_string[strlen(your_string)+2]='\0'
.
Now you use a loop which find you the first 0 near the figures:
1 2 3 4
|
for(i=strlen(your_string); i>=0; i--)
{ if(your_string[i]!='0')
break;
}
|
Now you have found the last figure. For example if you have 12323400000, the program found you the figure 4.
After that, you get the next 0,
your_string[i+1]=","
and replace this component with comma. You print the string and that's it. If you want to work with many numbers, you can put all these instructions in a loop. G - Luck.