gcc: error: stray ‘\342’ in program
April 17th, 2008
Lately I have been worried about a strange error message I have been getting from gcc, while trying to compile small C programs for my school's assignment.
The errors were of this form:
I couldn't see any obvious syntactical error in the mentioned line. This is how line #57 looks like:
At first sight, it looks pretty fine, but if you look closely you will see that the double quotation marks that surround the string literal are not the neutral (vertical) ones (like this: "). They are left and right double quotation marks respectively.
If I replace the quotation marks with the neutral ones, like this:
the problem is solved. So, if you are getting this kind of error maybe you should look closely to any double (or single) quotation marks in the erroneous line.
It is worth to say that I only had this problem when copying and pasting from the PDF files of my school, which were mostly likely exported by Micro$oft Word, which in turn had probably screwed the double quotation lines.
The errors were of this form:
giannis@giannis-vbox:~$ gcc program.c
program.c: In function ‘main’:
program.c:57: error: stray ‘\342’ in program
program.c:57: error: stray ‘\200’ in program
program.c:57: error: stray ‘\234’ in program
program.c:57: error: stray ‘\’ in program
...I couldn't see any obvious syntactical error in the mentioned line. This is how line #57 looks like:
printf(“\nThe linked list representation is...\n”);At first sight, it looks pretty fine, but if you look closely you will see that the double quotation marks that surround the string literal are not the neutral (vertical) ones (like this: "). They are left and right double quotation marks respectively.
If I replace the quotation marks with the neutral ones, like this:
printf("\nThe linked list representation is...\n");the problem is solved. So, if you are getting this kind of error maybe you should look closely to any double (or single) quotation marks in the erroneous line.
It is worth to say that I only had this problem when copying and pasting from the PDF files of my school, which were mostly likely exported by Micro$oft Word, which in turn had probably screwed the double quotation lines.
July 21st, 2009 at 10:36 am This due to missing ascii characters missing, The code might be copied from a PDF file. That is the code is not pure ascii.
December 14th, 2009 at 4:51 pm Thanks Giannis.
You helped me exactly.
I also copied from pdf and pasted it in .c file.
But now there is no problem.
January 26th, 2010 at 9:19 pm Thanks! Waqar Afridi
I was stuck for this and after reading your respond found out that " is different in pdf file..
March 23rd, 2010 at 1:53 am Thanks!!!
May 2nd, 2010 at 11:16 pm Thanks. Had the exact same type of problem copy/pasting some code from an OpenOffice doc, with a - symbol. It looked identical when I pasted it into Xcode, but apparently not all - symbols are the same character code
May 3rd, 2010 at 12:30 pm Thanks, this saved me a lot of head-scratching! I also copied some code from a PDF file and couldn't figure out what was wrong.
June 30th, 2010 at 3:35 am Thank you for your answer. That's what exactly the problem with me here. I shall keep the above mentioned solution in mind always. Grateful to you.
June 30th, 2010 at 9:21 am Thank you so much for this input.Same error occured for me also and was wondering what it is.Now it worked fine :)
July 12th, 2010 at 1:33 pm hey thank you so much...working fine now :)
August 22nd, 2010 at 3:14 pm Thank you