Printing " (double quote) in C

二次信任 提交于 2019-12-06 05:19:28

问题


I am writing a C code which reads from a file and generates an intermediate .c file. To do so I use fprintf() to print into that intermediate file.

How can I print " ?


回答1:


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", '"' );



回答2:


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\"");


来源:https://stackoverflow.com/questions/25411644/printing-double-quote-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!