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 "
?
Using \" escape sequence in printf, we can print the double quotes ("").
In C and C++ the single quote is used to identify the single character, and double quotes are used for string literals. A string literal “x” is a string, it is containing character 'x' and a null terminator '\0'. So “x” is two-character array in this case. In C++ the size of the character literal is char.
To have a double quote as a character in a string literal, do something like, char ident[] = "ab"cd"; The backslash is used in an escape sequence, to avoid conflict with delimiters. To have a double quote as a character, there is no need for the backslash: '”' is alright.
To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.
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", '"' );
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\"");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With