How to print f% d literally
How to print f% literally
This is probably the simple answer. But I cannot find the answer.
Let's say I want:
printf( "printf(\"%d\", x );" );
I want the result to be literally: printf( "%d", x );
Is there a way to do this? If I just put it in the code I wrote above, the number ends up in% d, but I don't want anything to fit there. I just want literal% d.
Escape %
with another %
:
printf( "printf(\"%%d\", x );" );
Okay, why aren't we doing some really safe programming practice here?
printf("%s", "printf(\"%d\", x );" );
You can use %%
for literal percent.
Use puts
or fputs
, this is the choice for unformatted text output
puts( "printf(\"%d\", x );");
to have it along with a trailing newline (which I think is a good idea) or
fputs( "printf(\"%d\", x );", stdout);
if you insist on no newline.
Double tap %
to "run away":
printf( "printf(\"%%d\", x );" );
^--