• Advertisement

Archived

This topic is now archived and is closed to further replies.

Quotations in character strings

This topic is 5061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I include quotation marks in a constant character string? For example:
printf (""abc"");
 
Will print out: "abc"

Share this post


Link to post
Share on other sites
Advertisement
Look up escape sequeneces in string literals.

"\"abc\""

Share this post


Link to post
Share on other sites
Escape the double quotes inside the string by putting a backslash directly in front of them.

Edit: FIRST POST!!! Oh... crap.

[edited by - bobstevens on April 15, 2004 1:24:14 PM]

Share this post


Link to post
Share on other sites
use \"
printf("\"abc\"");  
edit: 2 replies while I wrote that

[edited by - Eriond on April 15, 2004 1:24:24 PM]

Share this post


Link to post
Share on other sites
Use a slash before the quotes you want to be output:

printf("\"abc\"");

OK, sorry, just kidding, I realize 3 people have already said that.

Just for interest sake, you can also do:

printf("%cabc%c", '"', '"'); // using quote characters


or

printf("%cabc%c", 0x22, 0x22); // using ASCII codes for the quote character





[edited by - BriTeg on April 15, 2004 1:36:07 PM]

Share this post


Link to post
Share on other sites

  • Advertisement