Reputation: 1436
I am working on a legacy source code for computing data.
In order to debug few error conditions I have added the following printf in the code
printf("What???!!!!....\n");
The logs were maintained in a file and I was searching for the string "What???!!!!...." but II never found this because the output of it was coming as:
What??|!!!....
I have already wasted lot of time because of this unwanted output. Can someone please help me to identify the reason for this?
Upvotes: 0
Views: 127
Reputation: 213281
Trigraphs(3 character sequences) and Digraphs(2 character sequences) were added in C to help someone type some characters that are outside the ISO 646 character set, and don't have keyboard compliant to that.
Here's a paragraph from the Diagraph and Trigraphs Wiki page which specifies it clearly:
The basic character set of the C programming language is a subset of the ASCII character set that includes nine characters which lie outside the ISO 646 invariant character set. This can pose a problem for writing source code when the encoding (and possibly keyboard) being used does not support any of these nine characters. The ANSI C committee invented trigraphs as a way of entering source code using keyboards that support any version of the ISO 646 character set.
To print those two question marks, you can escape the 2nd one, or use string concatenation:
printf("What??\?!!!!....\n");
printf("What??" "?!!!!....\n);
Upvotes: 0
Reputation: 21
In the olden days, keyboards didn't necessarily include all of the characters required to write C programs. To allow those without the right keyboard to program, the earliest versions of C compilers used trigraphs and digraphs, uncommon two- or three-character combinations that would translate directly to a possibly absent key. Here is a list of digraphs and trigraphs for C:
http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C
??! is in the list, and it translates to | in the preprocessor.
One way to fix this is in the article I linked above: Separate the question marks with a \, or close the string and reopen it between the question marks. This is likely your best choice, being that you're working with legacy code.
Often, you can also disable digraphs and trigraphs with compiler switches. Consult your documentation for those details.
Upvotes: 1
Reputation:
the output is related to trigraph, the string
??! corresponds to |
Check your makefile for -trigraphs
Make sure to have more sensible prints now-on :-)
Upvotes: 2