开发者

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.


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.


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

 #define QUOTE(x) #x

and generate a printf as:

 printf(QUOTE(hello));


you are thinking of trigraphs

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

but " isnt on the list


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


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.

Sounds like a crappy tool.

It looks ugly, but you could try something like this:

static const char foo[] = {'H', 'e', 'l', 'l', 'o', 0};

printf(foo);

I also like dirkgently's suggestion to use # in a macro, however I wonder how that would do with spaces?


What do you think about using ´ instead of '?

I faced the same problem and tried to avoid it by replacing the text delimiter by something harmless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜