Error: stray '\277', '\357', '\273'

I copied a code off a website and Arduino is giving me a stray error. I've looked at some other forums about the same issues, but it's still not working. There isn't any characters in front of the line where arduino says there's an error.

Please do not post code and outputs as pictures, they're hard to read and impossible for us to see the entire code and/or test it.
Edit your first post here and remove the picture, then copy/paste your full code and mark it with the "<CODE/>" top button. Do the same per the serial output, marked with "<CODE/>" tags.
Lastly, always specify also which Arduino board (UNO? Mega? Nano?...) we're talking about, and if possible also a wirings draw.
Thanks.

Maybe the error is in a part of the code you did not post ?

You can cleanout your code using a regular expression. Exit status 1 stray '\342' in program - #10 by UKHeliBob gives the expression; the tool that you use depends on what you have available.

Alternatively, post your code here and next copy it back; it's said that that also works so you can give it a try.

You or somebody else used an overzealous tool that converts several ASCII characters into modern Unicode characters. That may be nice with documents for human reading but not so with source code for compilation, as you just noticed.

What has happened is that you copied some code that had unicode formatting characters added. This is probably because it was being displayed on a webpage when you copied it.

The fix is easy. Start a reply here and hit the little button at the top of the reply window that says <CODE> and it will give you a set of code tags. Paste your code into those code tags and then look at the preview window. It will put your code into a nice code block and it will scrub out any extra characters.

You can then copy the code back from that window and replace the code in the IDE and the offending characters will be gone.

Extended ASCII

To avoid this, paste your "copy" into gEdit/Notepad then "select-all, cut"

ASCII is a 7 bit code. There exists no 8 bit code page that merits the name "Extended ASCII", even if invented for Windows by Microsoft.

1 Like

Copying from PDF can cause "extended ASCII" or HTML (for example; &NBSP;) to be stored in the clipboard.

The byte sequence \357\273\277 is the UTF-8 encoding of the Unicode code point "U+FEFF ZERO WIDTH NO-BREAK SPACE". It's used as a Byte Order Mark. g++ doesn't support files beginning with that byte sequence so you'll need to remove those 3 bytes (maybe in another text editor with an option to remove the BOM?).

1 Like

Glad someone checked the octal math.

The BOM is at the very beginning of the file. Editors that are aware of it will generally honor it and preserve it for that file when saving, but it is not part of the file's content. This appears to be the case for Arduino IDE (at least on Linux -- the screenshot is on Windows). So try

  1. Create a blank file with the same name, but with a .cxx extension (also a valid C++ source file)
  2. In the original Select All and Copy; then Paste into the new file.
  3. Rename the original to .md (a valid non-code extension in the IDE) so the compiler will ignore it.
  4. Verify to compile

If the files are in the root of the sketch, you can use the kebab menu (hmm, the three dots are horizontal, so that's actually meatballs) in the top, to the right of all the tabs, just below the Serial Monitor. Use New Tab to create a file. You can also Rename and Delete from there. You can rename it back to .cpp if it works.

But that leads to the question: how did the BOM get there, and is it in other source files, which would cause a similar problem.

I think we better wait for the OP doing what we asked for more than 3 days ago, before going on with other considerations... :wink:

A post was merged into an existing topic: Error code 357 273 277