Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing " (double quote) in C

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 " ?

like image 327
Koushik Sarkar Avatar asked Aug 20 '14 18:08

Koushik Sarkar


People also ask

How do I print double quotes in printf?

Using \" escape sequence in printf, we can print the double quotes ("").

What is double quote in C?

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.

How do you add double quotes in C++?

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.

How do you quote a quote in C++?

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.


2 Answers

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", '"' );
like image 138
Vlad from Moscow Avatar answered Nov 03 '22 05:11

Vlad from Moscow


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\"");
like image 20
Keith Thompson Avatar answered Nov 03 '22 05:11

Keith Thompson