How to print %s in C?
10,031
Solution 1
No, %% outputs %, so the right syntax is:
printf("%%%s%%",string);
Solution 2
No.
Use %%%s%%
Solution 3
This solution absolves you from knowing how special printf characters like '%' or '\' should be printed.
#include <stdio.h>
int main(void)
{
const char str[]="MyString";
printf("%c%s%c",'%',str,'%');
return 0;
}
Author by
user299757
Updated on June 06, 2022Comments
-
user299757 almost 2 years
I want to print
"%SomeString%"
in C.Is this correct?
printf("%%s%",SomeString);