在C中打印"(双引号)"

Kou*_*kar 4 c printf quote double-quotes

我正在编写一个C代码,它从文件中读取并生成一个中间.c文件.为此,我使用fprintf()打印到该中间文件.

我怎么打印"

Vla*_*cow 8

您可以使用转义符号\"例如

puts( "\"This is a sentence in quotes\"" );
Run Code Online (Sandbox Code Playgroud)

要么

printf( "Here is a quote %c", '\"' );
Run Code Online (Sandbox Code Playgroud)

要么

printf( "Here is a quote %c", '"' );
Run Code Online (Sandbox Code Playgroud)


Kei*_*son 5

如果您只想打印一个"字符:

putchar('"');
Run Code Online (Sandbox Code Playgroud)

"不具有字符常量转义,因为字符常量被分隔',没有".(如果你愿意,你仍然可以逃避它'\"'.)

如果它是字符串文字中一些较大块输出的一部分,则需要将其转义,因此它不会被视为"文字的结束:

puts("These are \"quotation marks\"\n");
Run Code Online (Sandbox Code Playgroud)

要么

printf("%s\n", "These are \"quotation marks\"");
Run Code Online (Sandbox Code Playgroud)