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

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

当前回答

双字符“%”也适用于“. format(…)”。 示例(iDrawApertureMask == 87, fCornerRadMask == 0.05): csCurrentLine.Format(“\ %添加% 2 d C %, % 6.4 f * \ %”,iDrawApertureMask, fCornerRadMask); 给出csCurrentLine中(字符串内容)的期望值和期望值; “% ADD87C, 0.0500 * %”

其他回答

如果字符串中没有格式,你可以使用puts(或fputs):

puts("hello%");

如果字符串中有格式:

printf("%.2f%%", 53.2);

正如注释中所指出的,puts将一个\n附加到输出,而fputs则不会。

是这样的:

printf("hello%%");
//-----------^^ inside printf, use two percent signs together

是的,使用printf("hello%%");做完了。

双字符“%”也适用于“. format(…)”。 示例(iDrawApertureMask == 87, fCornerRadMask == 0.05): csCurrentLine.Format(“\ %添加% 2 d C %, % 6.4 f * \ %”,iDrawApertureMask, fCornerRadMask); 给出csCurrentLine中(字符串内容)的期望值和期望值; “% ADD87C, 0.0500 * %”

使用双%%:

printf("hello%%");