Reputation: 37177
What is the correct syntax for this code: is it:
printf("printf(\"\%d\",%s);", some_var);
or
printf("printf(\"%%d\",%s);", some_var);
Or something else?
Upvotes: 2
Views: 2150
Reputation: 283921
The second one. %d
is defined by printf, not the C language, so you need to escape it with the printf %%
, not a character escape.
A more complex example with a character escape sequence:
printf("printf(\"%%d\\n\",%s);\n", some_var);
Upvotes: 5
Reputation: 163318
The second one. In order to print a literal %
you need to escape them by appending another %
.
Upvotes: 3