i wrote simple arduino program to check a an array of ascii characters. Here is the program

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

}

void loop(){

char inByte;
  char arr[100]={0};
  char arrr[5]={'s','t','a','r','t'};
 int x=0;
 int y=0;
  do{

    arr[x]=arrr[y];
    x++;
    y++;
      }while(arr[0]!='s' && arr[1] !='t' && arr[2]!='a' && arr[3]!='r' && arr[4]!='t');
  if(arr[0]=='s' && arr[1] =='t' && arr[2]=='a' && arr[3]=='r' && arr[4]=='t'){
    delay(1000);
    Serial.println("done");}
    else{
    delay(1000);
    Serial.println("oo");
}

}

I want it to show "done" in serial monitor but instead it is printing "oo"..can any one tell me what is the problem in the program..thanks

没有正确的解决方案

其他提示

open braces for else part also

if(arr[0]=='s' & arr[1] =='t' & arr[2]=='a' & arr[3]=='r' & arr[4]=='t'){
    delay(1000);
    Serial.println("done");
}
else {
    delay(1000);
    Serial.println("oo"); 
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top