如何在C的printf中转义%(百分比)符号? [英] How to escape the % (percent) sign in C's printf?

查看:139
本文介绍了如何在C的printf中转义%(百分比)符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言中使用printf时如何转义%符号?

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: %%

使用您的示例:

printf("hello%%");

转义'%'符号仅适用于printf.如果您这样做:

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

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

它将打印:This is a's value: %%

这篇关于如何在C的printf中转义%(百分比)符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆