I want to convert a percentage to a string via sprintf. A workable way is like this:
sprintf(str, "%d", num);
strcat(str, "%");
But is there a way to only use sprintf to make it done?
I want to convert a percentage to a string via sprintf. A workable way is like this:
sprintf(str, "%d", num);
strcat(str, "%");
But is there a way to only use sprintf to make it done?
(Compiling an answer from comments, just to get this out of the list of unanswered questions.)
Printing a % via sprintf() is done via "%%", i.e. in your case thus:
sprintf(str, "%d%%", num);
Here is a quote from the helpful documentation:
A '%' is written. No argument is converted. The complete conversion specification is '%%'