M
M
malbaron2017-01-06 21:52:14
Programming
malbaron, 2017-01-06 21:52:14

What would be the format string for sprintf/printf for integers to separate digits with spaces?

You need to get a string like this: "1 234 567" out of the number 1234567.
How to do this with printf/sprintf, what should be the format string?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2017-01-06
@15432

Yes, it seems impossible ... Only manually write such a thing

void recursive_print(int number)
{
    int low_part = number % 1000;
    int high_part = number / 1000;
    if (high_part)
    {
        recursive_print(high_part);
        printf(" ");
    }
    printf("%d", low_part);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question