如何逃避C的printf%符号? [英] How to escape the % sign in C's printf?
本文介绍了如何逃避C的printf%符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何用C使用时,的printf
逃脱%标志?
的printf(你好\\%); / *不喜欢这样的* /
解决方案
您可以通过发布双'%'这样的逃避它: %%
使用你的例子:
的printf(你好%%);
逃离'%'标志仅供printf的。如果你这样做:
的char a [5];
的strcpy(一,%%);
的printf(这是一个值:%S \\ n,一);
这会打印:这是一个值:%%
How do you escape the % sign when using printf
in C?
printf("hello\%"); /* not like this */
解决方案
You can escape it by posting a double '%' like this: %%
Using your example:
printf("hello%%");
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: %%
这篇关于如何逃避C的printf%符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文