C String manipulation/conversion help

Hi,

I need to be able to take an unsigned long value and convert it to a string that is separted by commas.

So for example, if i have the unsigned long value 1372516, I'm supposed to somehow get "1,372,516".

Can someone please give me the right direction to go about doing this? Thanks.

This will take some work. You will need to write a little function to handle this kind of thing. As a hint,
printf("i = %d,%3.3d,%3.3d\n",i/1000000, i/1000%1000, i%1000);
would work with the number you posted. But if the number was too small or negative, there would be a problem. A negative number would be a clear problem, but you might want the leading zeros that would happen with small numbers. So you need to decide on your requirements. Do have the possibility of a a negative number? If so how should it be displayed? And so on.

ok thx for ur help. I got it but it took me 4 hours and I believe there's a better way to do it but im busy as it is so dont have time to figure it out. I wrote a really stupid method and basically it's a hack but it works perfectly so I'll just stick with it. Luckily the prof doesn't examine the source code or else I'd lose marks for sure.

Thanks again.

The rules state:
(6) Do not post classroom or homework problems.

I will close this thread.