Chris_45 Chris_45 - 3 years ago 163
C Question

How to escape the % (percent) sign in C's printf?

How do you escape the % sign when using

in C?

printf("hello\%"); /* not like this */

Answer Source

You can escape it by posting a double '%' like this: %%

Using your example:


Escaping '%' sign is only for printf. If you do:

char a[5];
strcpy(a, "%%");
printf("This is a's value: %s\n", a);

It will print: This is a's value: %%

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download