gcc: error: stray ‘342’ in program

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.

This entry was posted in Uncategorized. Bookmark the permalink.

36 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

  11. sarath says:

    thaku u so much……..

  12. Oscar says:

    sweet man,
    that was really smart…it seems like I’m not the only one that copy-paste code, sometimes =)

  13. Alfred says:

    Thanks! helpful

  14. Anonymous says:

    thanks. :)

  15. Jilu says:

    Thanks alot it really worked :)

  16. hai says:

    thanq u so much!

  17. karan says:

    Thanks !!!! just need to change my keybord layout to get correct ascii

  18. Neha says:

    I didnt copy it from any pdf. Though i checked the quotes , problem persists…

  19. Elinostro says:

    Hi, im from Colombia. I just want give you a congratulations ’cause you have help me. Thanks a lottt!!

  20. Elham says:

    Thank You.

  21. Jeshwanth says:

    Hey Thanks…

  22. Sandeep says:

    Hey Friends, I got an error

    /usr/examples/xmpl-hello/hello.c:52:2: error: stray ‘342’ in program
    ../usr/examples/xmpl-hello/hello.c:52:2: error: stray ‘210’ in program
    ../usr/examples/xmpl-hello/hello.c:52:2: error: stray ‘222’ in program
    ../usr/examples/xmpl-hello/hello.c:52:47: error: expected ‘)’ before ‘startTime’

    The 52 line code is below… can anyone help me out

    uint64_t msecs = bench_tsc_to_msc(stopTime−startTime);

  23. chinna says:

    thanks a lot really it helped me

  24. nuria says:

    Thanks, found it helpful!

  25. thanker says:

    thanks. I encountered the same exact problem. Thank you!!

  26. Venus says:

    Oh man!!!…thank u very much!…..u saved meeeeeee!!!!:)

  27. pradeep says:

    thnx brother!!!

  28. pradeep says:

    thnx bro…

  29. ritwick says:

    helpful !

  30. Thankfull One says:

    Thanks a lot. saved my day

  31. mydhili warrier says:

    ThankYou……:) It helped me a lot……………:) :)

  32. Unknown says:

    Thanks

  33. n00b says:

    thanks, bro! no more head scratching!

  34. Anonymous says:

    Thanks! It really helped!

  35. Gowtham says:

    yeah!! It’s Correct. thank you. dude

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>