Print "(double quote) in C

I am writing C code that reads from a file and generates an intermediate file .c

. For this I use fprintf()

to print to this intermediate file.

How to print "

?

+3


source to share


2 answers


You can use escape character \"

For example

puts( "\"This is a sentence in quotes\"" );

      

or



printf( "Here is a quote %c", '\"' );

      

or



printf( "Here is a quote %c", '"' );

      

+7


source


If you just want to print one character "

:

putchar('"');

      

"

does not need to be escaped in a character constant, since character constants are character-delimited '

, not "

. (You can still avoid this if you want:. '\"'

)

If it is part of some larger chunk of output in a string literal, you need to escape it so that it is not considered a closing "

literal:



puts("These are \"quotation marks\"\n");

      

or

printf("%s\n", "These are \"quotation marks\"");

      

+4


source







All Articles