-5

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

user2736738
  • 30,591
  • 5
  • 42
  • 56
MSD
  • 5
  • 3

2 Answers2

0
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 %%.

user2736738
  • 30,591
  • 5
  • 42
  • 56
0

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.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483