I have a python method calling a c++ dll method, that contains printf().
typical call:
method ("something")
But now I have to be able to call something like
method("%x %y %z")
And it is crashing.
I have escaped the %, with a very simple
if msg:
msg = msg.replace( "%", "/%" )
and it seemed to work for the case where there was only one. (Don’t know exactly what effects it has on the text itself… )
So I tested with more than one, and I got a Debug Assertion Failure – Expression (“Incorrect format specifier”, 0).
Edit: After the accepted answer, the solution:
if msg:
msg = msg.replace( "%", "%%" )
The way to escape percent signs in
sprintf()and the like is to double them (i.e.%%). But the code itself needs to be fixed by using"%s"as the first argument instead of the passed string.