How do I print a percent sign with sprintf()?. I want to do something like this: sprintf(buf, "Value: %3d%%", value); According to ANSI C this should give "Value: 98%" or the like. But it seems that sprintf doesn't know the double precent seqence (printf does!). sprintf(buf, "Value: %3d%s", value, "%"); doesn't work either. sprintf(buf, "Value: %3d%s", value, "%%"); works but should not! Is this a bug or am I doing something stupid? Regards, Ralf
Silly me! I found the error: it was my mistake. So forget it! FYI: the string formatted with sprintf() was output with a printf() later and thus used as the new format string, this format string mustn't have a single percent sign (will be misinterpreted). Using puts() instead solved the problem. Ralf
if you wanted to do the origional way you would need 4 %percent signs. sprintf(buf, "Value: %3d%%%%", value); the sprintf would convert the 4 to 2 then the printf would get the 2 it needs to print the 1.