How to print a % (percent) with sprintf ?

Hi,
In the following function, I need to replace Percent with %. But when I do that, it is detected as a format specifier.

sprintf (buffer,"Volt,Volt,C,C,Percent")

How can I do this ?

Thanks,

Use "%%"

https://avrdudes.github.io/avr-libc/avr-libc-user-manual-2.2.0/group__avr__stdio.html#gaa3b98c0d17b35642c0f3e4649092b9f1

3 Likes

Thanks !
That worked and looks easy once you know it.

Indeed the Conversion Specifier for % is % so you write %%

Note that if you have nothing to format, you don't need to use sprintf() (or better snprintf()) just use strcpy (or better strncpy() or strlcpy()) and you don't need to worry about the text.

strlcpy (buffer,"Volt,Volt,C,C,%", sizeof buffer);
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.