'??' gets converted into '^' if I compile mn VC++ program and run it
e.g.
sprintf( ch, "??")
prints out
^
But if I run the same code in Turbo C/C++, there is no such problem. Why is it happening on VC++ on Windows?
'??' gets converted into '^' if I compile mn VC++ program and run it
e.g.
sprintf( ch, "??")
prints out
^
But if I run the same code in Turbo C/C++, there is no such problem. Why is it happening on VC++ on Windows?
The ??
usually sequence starts a trigraph, but the sequence "??" isn't a trigraph so it shouldn't be interpreted as such - maybe there's a bug in the compiler - exactly which version are you using, and what's the exact code (including variable declarations)?
This code prints "??" in several versions of MSVC 6 through VS 2010 as you might expect:
char ch[20];
sprintf( ch, "??");
printf( "%s\n", ch);
But replace the snprintf()
line with:
sprintf( ch, "'??'");
and the output becomes "'^
" (except in VS 2010).
A quick test shows that VS 2010 disables trigraph support by default (it prints out "'??'
" in the 2nd test). In VS 2010 you have to explicitly enable trigraph support using the /Zc:trigraphs
option. Nice.
For more details on what trigraphs are, see: http://stackoverflow.com/questions/1234582/purpose-of-trigraph-sequences-in-c
Are you sure it was a double-quote and not a single-quote? If it was ??', then you've just encountered a trigraph, which is a "feature" that really should be removed, but isn't due to IBM not migrating to UTF-8 from EBCDIC. (Trigraphs were considered for removal when C++0x was still open for changes, but the move to get trigraphs removed were vehemently blocked by IBM and its representatives at the ISO C++ committee).
??
alone is not a trigraph, although ??'
corresponds to ^
.
Perhaps you typed it here different from what you have in code and you can't see the trailing single quote in your string because it's too close to the closing quote.
So in code you probably have:
sprintf( ch, "??'");