C语言 在 C 中打印 "(双引号)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25411644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Printing " (double quote) in C
提问by Koushik Sarkar
I am writing a C code which reads from a file and generates an intermediate .cfile.
To do so I use fprintf()to print into that intermediate file.
我正在编写一个 C 代码,它从一个文件中读取并生成一个中间.c文件。为此,我使用fprintf()打印到该中间文件中。
How can I print "?
如何打印"?
回答by Vlad from Moscow
You can use escape symbol \"For example
您可以使用转义符号\"例如
puts( "\"This is a sentence in quotes\"" );
or
或者
printf( "Here is a quote %c", '\"' );
or
或者
printf( "Here is a quote %c", '"' );
回答by Keith Thompson
If you just want to print a single "character:
如果您只想打印单个"字符:
putchar('"');
The "doesn't have to be escaped in a character constant, since character constants are delimited by ', not ". (You can still escape it if you like: '\"'.)
在"不具有字符常量转义,因为字符常量被分隔',没有"。(如果你愿意,你仍然可以逃避它:'\"'。)
If it's part of some larger chunk of output in a string literal, you need to escape it so it's not treated as the closing "of the literal:
如果它是字符串文字中较大输出块的一部分,则需要对其进行转义,以免将其视为"文字的结束:
puts("These are \"quotation marks\"\n");
or
或者
printf("%s\n", "These are \"quotation marks\"");

