Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the alternate character combination for the double quote character in C/C++?

I've not had the Kernighan and Ritchie C reference in years, but I remember that there was a page in there that talked about how to enter characters that were unavailable to you. (WAY back in the day, some keyboards lacked characters like ", ~, etc.)

To be clear, let me give an example. I'm not looking for a way to get quotes in strings, but rather, I want to replace this:

printf("foo");

with this:

printf([alternate sequence]foo[alternate sequence]);

For the curious, I have an automated process that involves generating C/C++ code, but the (closed source) commercial tool involved strips quotes in its data streams and the documentation is quite clear on the fact that they do not provide a way to escape them.

EDIT:

Wow, I hadn't expected such a heavy response. This might merit a little more detail on my process. I'm doing automated build systems, which means that I live with certain restrictions when it comes to changing the code I'm compiling. For now, we have to live with the assumption that I have to get a string, spaces and all, into a preprocessor definiton. I already went down the 'PreprocessorDefinition' road. This left me with my usual fallback: Define the string in the operating environment and have the project file set the definition from there:

Preprocessor Definitions     WIN32;_DEBUG;THINGIE=$(THINGIE)

The hope was that I could get around MSVC's stripping of quotes in anything handed to the build with /D using a trigraph, by doing something like this in my build automation script:

ENV['THINGIE'] = "??''Yodeling Monkey Nuggets??''"
run_msbuild_command

I guess it's time for a plan C.

like image 609
Sniggerfardimungus Avatar asked Feb 05 '10 18:02

Sniggerfardimungus


People also ask

How do you put a double quote in a string?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.

How do you add double quotes to a string 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.

What is a quote character?

Quoting is used to remove the special meaning of characters or words: quotes can disable special treatment for special characters, they can prevent reserved words from being recognized as such and they can disable parameter expansion.


4 Answers

You are looking for a trigraph for " character? I don't think one exists.

Trigraphs don't exist for all characters. Only a few characters have trigraph sequences.

like image 74
mmx Avatar answered Nov 15 '22 07:11

mmx


None as per the standard. Try including a header with a macro:

 #define QUOTE(x) #x

and generate a printf as:

 printf(QUOTE(hello));
like image 36
dirkgently Avatar answered Nov 15 '22 07:11

dirkgently


you are thinking of trigraphs

 Character   Trigraph
 [           ??(
 \           ??/
 ]           ??)
 ^           ??'
 {           ??<
 |           ??!
 }           ??>
 ~           ??-
 #           ??=

but " isnt on the list

like image 20
pm100 Avatar answered Nov 15 '22 07:11

pm100


I think you're talking about trigraphs. As far as I've read, there is not one for the " character.

like image 23
Carl Norum Avatar answered Nov 15 '22 06:11

Carl Norum