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:

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.

10 Responses to “gcc: error: stray ‘\342’ in program”

  1. Waqar Afridi Says:
    This due to missing ascii characters missing, The code might be copied from a PDF file. That is the code is not pure ascii.
  2. Jnanesh Says:
    Thanks Giannis.
    You helped me exactly.

    I also copied from pdf and pasted it in .c file.

    But now there is no problem.
  3. Hyun Says:
    Thanks! Waqar Afridi
    I was stuck for this and after reading your respond found out that " is different in pdf file..
  4. hermione Says:
    Thanks!!!
  5. Mark McRobie Says:
    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
  6. James Says:
    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.
  7. Kunal Kale Says:
    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.
  8. Sruthi Says:
    Thank you so much for this input.Same error occured for me also and was wondering what it is.Now it worked fine :)
  9. neha Says:
    hey thank you so much...working fine now :)
  10. sezen Says:
    Thank you

Leave a Reply