tags:

views:

75

answers:

2

Hey,

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?

+3  A: 

The second one. In order to print a literal % you need to escape them by appending another %.

Jacob Relkin
+3  A: 

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);
Ben Voigt
ok ty to both for the quick answer +1 to you and jacob
fmsf
lol you'll get the correct answer because you remembered me i was forgeting to put a \n in the end of my printf :P
fmsf
you're very welcome
Ben Voigt