I need to print a string with an integer an the symbol % after it.
Here is what i try:
sprintf(txt, "%d",CurrentArrayValue,'%');
But my result is only my number. None symbol after that
I need to print a string with an integer an the symbol % after it.
Here is what i try:
sprintf(txt, "%d",CurrentArrayValue,'%');
But my result is only my number. None symbol after that
sprintf(txt, "%d%%",CurrentArrayValue);
This will do the trick.
From standard §7.21.6.1 C11 standard N1570
%
A
%character is written. No argument is converted. The complete conversion specification shall be%%.
Use, simply a %% in the format string:
sprintf(txt, "%d%%",CurrentArrayValue * 100);
Your '%' is ignored by sprintf since your formatting string indicates to the function that only one additional argument is needed.
You have to multiply CurrentArrayValue by 100 yourself by the way: I slipped that in to the function parameter list.