Arduino build error

error: stray '\342' in program

The code holds a character that is not plain text: a curly quote, a long dash, or a non-breaking space. C++ only reads straight quotes and ordinary spaces.

  • Build error
  • 2 common causes
  • Seen 2,761 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
sketch.ino:4:20: error: stray '\342' in program
sketch.ino:4:21: error: stray '\200' in program
sketch.ino:4:22: error: stray '\234' in program
exit status 1

The numbers in the message are the bytes of that character. They almost always come from code copied from a web page, a document or a chat.

Mokxi's compiler, clang, words it as a character that is not allowed, with its Unicode number, for example U+201C for a curly quote.

Causes

The 2 usual causes with the fix

1Curly quotes around a string

Word processors and web pages turn straight quotes into curly ones. Retype both quotes in the editor.

Broken
void setup() {
  Serial.begin(9600);
  Serial.println(“hello”);
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  Serial.println("hello");
}

void loop() {
}

Mokxi’s build tab says: A character here was pasted from a web page or a document

Try this fix in Mokxi

2A long dash instead of a minus

An en dash or em dash looks like a minus sign and is a different character. Type a plain hyphen.

Broken
void setup() {
  Serial.begin(9600);
  int x = 5 – 3;
  Serial.println(x);
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  int x = 5 - 3;
  Serial.println(x);
}

void loop() {
}

Try this fix in Mokxi

FAQ

Questions and answers

What does "stray '\342' in program" mean?

The sketch contains a character the compiler cannot read. The three numbers \342 \200 \234 together are one curly quote.

Why do I only see it after pasting code?

Web pages and documents swap plain characters for typographic ones. Retype the quotes and dashes in the editor.

Does the \302 version mean the same thing?

Yes. \302 starts a non-breaking space. Delete the space and type it again.