1

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.

Ephraim
  • 63
  • 1
  • 7
  • 1
    [How to format a number from 1123456789 to 1,123,456,789 in C?](//stackoverflow.com/q/1449805) – 001 Jul 03 '20 at 11:14
  • @JohnnyMopp Although helpful, I wonder if this can be seen as strict duplicate. This question asks not only for the `,` notation. – RobertS supports Monica Cellio Jul 03 '20 at 11:28
  • 2
    @RobertSsupportsMonicaCellio Yes. I did not vtc as dupe. Just put that there for OP to see some examples of ways to accomplish the task. There are plenty that don't use `printf("%'d")` – 001 Jul 03 '20 at 11:34
  • Did you try searching for an answer first = before throwing a question here? – iAmOren Jul 03 '20 at 12:06

1 Answers1

0

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 ;-)