Help on Stray "\342" in program

Hello everybody
I am new to this C++ programming
Currently, I am learning how to use array of structure

Intent of code :

  1. Input into an array (i.e. that has a given structure)
  2. Print out to verify information correctness

I am getting an “Stray “\342” in program” error at last println of second “for” loop
Could not figure out why it is doing this.
Any help or advice is much appreciated.

#include <string.h> 

typedef struct part
{
Int   loc;
String  name;
String  file;
}list;

Void setup()
{
  Serial.begin(115200);
  delay(1000);
  Int i;
  list pos[5];      // array … pos1, pos2, etc…basically an array of structure “data” in it
  for (i=0; i<4; i++)
  {
    Serial.println (“\n\t Enter the owner’s location,name and file of part %d \n”,i+1);
    Serial.read(“%d%s%s”,&pos[i].loc,&pos[i].name,&pos[i].file);
    Serial.flush();
  }// for input data
  
  Serial.println("Done with input");
  
  for (i=0; i<4; i++)
  {
    Serial.println("Done with printout database");
    Serial.println(“location=%d\tname=%s\tfile=%s \n",pos[i].loc,pos[i].name,pos[i].file);
  }  // for print all info

  Serial.println("Done with printout database");
} // setup
Void loop()
{}
Void setup

That'll need fixing too

Void loop()

Int i;And those.

This is caused by a hidden character in your code, probably gotten by copying and pasting from some website. If you click the "Select" button on the code box of your forum post and then paste that over your sketch the problem will be solved because when you post the code on the forum using code tags it removes the invisible characters. At that point you'll find a bunch of new problems but they are all pretty easy to fix with a close look at the error message, the code, and the reference pages associated with that code.

Thanks AWOL. Fix that..still having same problem .... Hmmm

888Tan: still having same problem

Did you try what I told you to do?

Copy the code that you posted in the opening post and paste it in a new sketch. Compile and the ‘stray’ error should be gone.

Hi Pert

Replace all my double quote ’ " ’

Also …did copy to new page …

Error went away …thanks … however I am getting a new error.
Here is my revised code

Error:
exit status 1
no matching function for call to ‘HardwareSerial::read(const char [7], int*, String*, String*)’

#include <string.h> 

typedef struct part
{
  int loc;
  String name;
  String file;
}list;
void setup()
{
  Serial.begin(115200);
  delay(1000);
  list pos[5];      // array … pos1, pos2, etc…basically an array of structure “data” in it
  for (int i=0; i<4; i++)
  {
    Serial.println ("Enter owner’s loc,name and filename");
    Serial.read ("%d%s%s",&pos[i].loc,&pos[i].name,&pos[i].file);
  }// for input data
  
  Serial.println("Done with input");
  
  for (int i=0; i<4; i++)
  {
    Serial.println("Done with printout database");
    Serial.println("location=%d\tname=%s\tfile=%s \n",pos[i].loc,pos[i].name,pos[i].file);
  }  // for print all info

  Serial.println("Done with printout database");
} // setup
void loop()
{}

When you have a problem take a look at the reference page for the function at the line where the error is: https://www.arduino.cc/en/Serial/Read Do you see the problem now?

Thanks for everybody's help. I will go back and revisit all my code and get more familiarize with Serial.read().

Cheers !

/*
SIM800L gsm module on LiPo battery
Dec 2015

do not connect to 5V logic, use 3.3V option or power Arduino from LiPo
GND
TX to D8
RX to D9
RST to D7

LED on D11 green = system status:: on=ready blinking=starting
LED on D12 red = call status:: on=in call blinking=ringing
button on D4 : call number 1 and answer/hang up
button on D5 : call number 2 and answer/hang up
*/

#include "Adafruit_FONA.h"
SoftwareSerial sim800(8,9);

char phone_number1[]=”+xxxxxx”; // put phone number here, international format, no spaces
char phone_number2[]=”+xxxxxx”;
unsigned long time_pressed4;
unsigned long time_pressed5;
boolean SIMok = false;
int current_status;

void setup() {
delay(5000);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);

pinMode(11, OUTPUT); // green LED
pinMode(12, OUTPUT); // red LED
digitalWrite(11, HIGH); // blink green and red LED
digitalWrite(12, HIGH);
delay(500);
digitalWrite(11, LOW);
digitalWrite(12, LOW);

pinMode(7, OUTPUT); // sim800 RESET
digitalWrite(7, LOW);

Serial.begin(9600);
sim800.begin(9600);

Serial.print(F(“Testing sim800 module.. “));
SIMok = false;
for (int i=0;i<3;i++) {
if (simReady()) {
SIMok = true;
break;
}
}

if (SIMok) simDetails(); // get some details on SIM
else { // if SIM not OK then blink RED forever
for (;;) {
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
}
}
digitalWrite(11, HIGH); // green LED on for SIM ok
}

void loop() {

current_status = checkStatus();
// Serial.println(current_status); // 48: ready 51: ringing 52: in call

if (current_status == 52) { // IN CALL (should be 4 according to datasheet)
Serial.println("52: in call");
digitalWrite(12, HIGH); // red LED on when in call
delay(500);
if (!digitalRead(4) || !digitalRead(5)) { // if push any button hang up call
digitalWrite(12, LOW); // red LED off after hang up
sim800.println("ATH");
Serial.println(F("Hanging up call"));
simReply();
}
}
else {
if (current_status == 51) { // RINGING (should be 3 according to datasheet)
Serial.println(F("51: incoming call.."));
digitalWrite(12, HIGH); // blink red LED when ringing
delay(500);
digitalWrite(12, LOW);
if (!digitalRead(4)|| !digitalRead(5)) { // if push any button answer call
digitalWrite(12, HIGH); // red LED on when in call
sim800.println("ATA");
Serial.println(F("Answering call"));
simReply();
}
}
else {
digitalWrite(12, LOW);
if (digitalRead(4)) {time_pressed4 = millis(); // button not pushed
else if (millis() - time_pressed4 > 500) {simCall(phone_number1); // button pushed, call if long push

if (digitalRead(5)) {time_pressed5 = millis();} // button not pushed
else if (millis() – time_pressed5 > 500) {simCall(phone_number2); // button pushed, call if long push
}
}
}

boolean simReady() { // SIM READY

digitalWrite(7, LOW); // hardware reset after sleep RST
delay(1000);
digitalWrite(7, HIGH);

// time to startup 3 sec
for (int i=0;i<6;i++) {
digitalWrite(11, HIGH); // green LED blink
delay(250);
digitalWrite(11, LOW);
delay(250);
}

sim800.println("AT");
delay(100);
if (sim800.find("OK")) {
Serial.println(F("OK"));
Serial.print(F("Registering on the network.."));
for (int i = 0; i<20; i++) {
// time to register on network 2.5 sec
for (int i=0;i<5;i++) {
digitalWrite(11, HIGH); // green LED blink
delay(250);
digitalWrite(11, LOW);
delay(250);
}
Serial.print(".");
sim800.println("AT+CREG?"); // possible replies: 0,0=not registered 0,1=registered on home network 0,2=not registered but searching 0,3=denied 0,4=unknown 0,5=roaming
delay(1000);
if (sim800.find("0,1")) {
Serial.println(F(" OK"));
return true;
}
}
Serial.println(F("failed to register for 1min, will reset sim800"));
return false;
}
else
{
Serial.println(F("sim800 module not OK, please check"));
return false;
}
}

void simReply() { // SIM REPLY
delay(500);
while (sim800.available()) {
char c = sim800.read();
// if (c != '\n') Serial.write(c); // replace new line with space
// else Serial.print(" ");
delay(5);
}
// Serial.println();
}

int checkStatus() { // CHECK STATUS FOR RINGING or IN CALL

sim800.println("AT+CPAS"); // phone activity status: 0= ready, 2= unknown, 3= ringing, 4= in call
delay(500);
if (sim800.find("+CPAS: ")) { // decode reply
char c = sim800.read();
simReply();
return c;
}
else return -1;
}

void simCall(char number[]) {

digitalWrite(12, HIGH);
Serial.print("Start call.. ");

sim800.println("AT+CREG?"); // possible replies: 0,0=not registered 0,1=registered on home network 0,2=not registered but searching 0,3=denied 0,4=unknown 0,5=roaming
delay(1000);
if (sim800.find("0,1")) {
Serial.println(F("network connection still OK"));
simReply();
}
else {
SIMok = false;
for (int i=0;i<3;i++) {
if (simReady()) {
SIMok = true;
break;
}
}
if (!SIMok) { // SIM not ok, blink RED forever
for (;;) {
digitalWrite(12, HIGH);
delay(100);
digitalWrite(12, LOW);
delay(100);
}
}
}

Serial.print("Calling number ");
Serial.println(number);
String cmd; // make call command
cmd = "ATD";
cmd += number;
cmd += ";";
sim800.println(cmd);
delay(1000);
simReply();
}

void simDetails() {
Serial.print(F("operator:"));
sim800.println("AT+COPS?"); // OPERATOR
delay(500);
if (sim800.find(":")) { // decode reply
while (sim800.available()) {
char c = sim800.read();
if (c != '\n') Serial.write(c); // replace new line with space
else Serial.print(" ");
delay(5);
}
}
else Serial.print(F("n/a"));
Serial.println();

Serial.print(F("signal strength:"));
sim800.println("AT+CSQ"); // SIGNAL STRENGTH
delay(500);
if (sim800.find(":")) { // decode reply
while (sim800.available()) {
char c = sim800.read();
if (c != '\n') Serial.write(c); // replace new line with space
else Serial.print(" ");
}
}
else Serial.print(F("n/a"));
Serial.println();

Serial.print(F("battery level:"));
sim800.println("AT+CBC"); // BATTERY LEVEL
delay(500);
if (sim800.find(":")) { // decode reply
while (sim800.available()) {
char c = sim800.read();
if (c != '\n') Serial.write(c); // replace new line with space
else Serial.print(" ");
}
}
else Serial.print(F("n/a"));
Serial.println();

sim800.println("AT+CLVL=80"); // set speaker volume 0-100
simReply();
sim800.println("AT+CRSL=80"); // set ringer volume 0-100
simReply();
sim800.println("AT+CMIC=0,12"); // set mic to gain level 0-15
simReply();
// ring tone AT+CALS=5,1 to switch on tone 5, 5,0 to switch off
sim800.println("AT+CALS=19"); // set alert/ring tone
simReply();

Serial.println("Ready");
}

johnguy: ... ...

Did that solve the OPs problem? With your missing curly braces, I doubt it.

Use tools -> autoformat in the IDE to properly indent. After that, each function should start at the beginning of a line. If not, you have a mismatch between number of { and number of }.

What special character do I use because when i verify it, it wont accept it. I attached the code below, someone please help. The error is in line 29.

Real_one_stiil_test.ino (2 KB)

Do this:

  • Sketch > Verify/Compile
  • After the compilation fails, scroll the black console window at the bottom of the Arduino IDE window all the way to the top.
  • Start working your way down through the "stray '\nnn' in program" errors, fixing them one by one. The error shows the line number in the sketch where the error is and the contents of that line.

Here's an example to get you started. The first error:

Real_one_stiil_test:4:18: error: stray '\342' in program

 char* password = „123“; //We set the password. In this case „123“

                  ^

The "Real_one_stiil_test:4:18" part of the error tells you that the error is in the file Real_one_stiil_test, at line 4, column 18. The "^" indicates the position of column 18.

We know that string literals are supposed to be wrapped in quotes. Some idiotic website software decided that wasn't "pretty" enough and changed to those weird quotes, which are not valid C++. So you need to change line 4 back to using proper quotes:

char* password = "123"; //We set the password. In this case „123“

You'll notice that there are a few more error in the console about line 4, but just changing those two characters will have fixed all of those errors so you can proceed to the next set of errors at line 9.

I had much the same problem. I cut/pasted the sketch into a text file (.txt) then put it back - & all good! You can't see the characters that are causing trouble. I think you can acquire the stray code by copy/paste code from a website.Good luck.

Often, you can fix the error by pasting the code into a forum message using code tags, clicking the "Preview" button, then copying the code from the preview back to the Arduino IDE. That's more standardized than using a random text editor since different editors or different editor settings may handle the bad characters differently.

I tried the forum trick on zman2792's code but it didn't work in this case. I think it's more helpful with the non-printing characters.

/**/

/libraries/
#include “Display.h”
#include <Streaming.h>

/variables/
byte wheelOfFortuneStates = { … };
byte displayElements[5] = { 0 };
byte wheelIndex, pos, seg;
enum BlinkState blink_state = ON;
long animateTime = 0;
int lastButton1State = HIGH;
long lastButton1Time = 0;

/configuration/
void setup()
{
/serial active/
Serial.begin(9600);

/input for keys/
pinMode(BUTTON1PIN, INPUT_PULLUP);
pinMode(key2, INPUT_PULLUP);

/output for LED/
pinMode(red_LED, OUTPUT);

/**/
Display.clear();
}

bool blinkDisplayStep(int period)
{
switch (blink_state)
{
case ON:
Display.on();
blink_state = DELAYON;
animateTime = millis();
break;
case DELAYON:
if ((millis()–animateTime) > period / 2)
{
blink_state = OFF;
}
break;
case OFF:
Display.off();
blink_state = DELAYOFF;
animateTime = millis();
break
case DELAYOFF:
if ((millis()–animateTime) > period / 2)
{
blink_state = ON;
return true;
}
break;
}
return false;
}

enum ButtonState {
PRESSED,
RELEASED,
UNKNOWN
};

enum BlinkState
{
ON,
OFF,
DEALYON,
DELAYOFF
};

void wheelStep()
{
byte elementIndex = wheelIndex;
for (byte i = 0; i < 4; i++) {
displayElements = wheelOfFortuneStates[elementIndex];

  • elementIndex = (elementIndex + 1) % 10;*
  • }*
  • wheelIndex = (wheelIndex + 1) % 10; // cyclic index.*
  • …*
  • Display.show(displayElement);*
    }
    enum ButtonState readDebouncedButton1()
    {
  • int buttonState = digitalRead(BUTTON1PIN);*
  • if (buttonState != lastButton1State)*
  • {*
  • lastButton1State = buttonState;*
  • if ((millis() - lastButtonTime) > 20)*
  • {*
  • lastButtonTime = millis();*
  • if (buttonState == LOW)*
  • {*
  • return PRESSED; // button is pressed.*
  • }*
  • else*
  • {*
  • return RELEASED;*
  • }*
  • }*
  • }*
  • return UNKNOWN; // button is not pressed.*
    }
    /main/
    void loop()
    {
  • wheelStep();*
  • delay(100);*
  • for (int i = 0; i < 5; i++)*
  • {*
  • bool result = false;*
  • while (!result)*
  • {*
  • result = blinkDisplayStep(1000);*
  • }*
  • }*
  • int value;*
  • value = readDebouncedButton1();*
  • if (value == PRESSED)*
  • {*
  • digitalWrite(selected_LED, HIGH);*
  • }*
    }

Do you have a question?
Code tags?