Is there a way I can split my output with a separator in C. for instance, I have processed a calculation, and the output is... 10000. Is there a way of making it 10,000 or 10 000?
THANKS, A LOT... your answers are most valued.
Is there a way I can split my output with a separator in C. for instance, I have processed a calculation, and the output is... 10000. Is there a way of making it 10,000 or 10 000?
THANKS, A LOT... your answers are most valued.
AFAIK there is no function available for this. But you could write an algorithm at your own by converting the number to a string, assign this string to an array of char
with enough space and then print each character separately. You need two parameters for this function more, 1. the character displayed as "place" and optionally 2. an offset at where you want the "place" character to be displayed.
To split an integer to a string you can use sprintf()
as suggested in this answer.
I'm too busy to write such function for you at the moment. But I'm sure others will help you further with this idea.
Also take a look at:
How to format a number from 1123456789 to 1,123,456,789 in C?
as find out by @JohnnyMopp in the comments for the ,
notation only.
Good Luck ;-)