Comparing byte arrays makes nonsense

The problem in this code is that comparison of byte arrays goes wrong and may be you have idea why is it happening?

the code compares byte two byte arrays: 1 stored array and 2 array from user input. The sizes of arrays are same, but when it gets to comparison Arduino sometimes says that array are same while they are totally different.

Here is the code:

byte button[] = { 
  10, 11, 12 };

byte arcount = 0;

byte input[4];

byte storray[] = {
  1,2,3,2};


void setup() {
  // put your setup code here, to run once:
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(8, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  if (digitalRead(10) == HIGH){
    input[arcount] = 1;
    arcount++;
    delay (200);
    Serial.println("1pressed");
  }
  if (digitalRead(11) == HIGH){
    input[arcount] = 2;
    arcount++;
    delay (200);
    Serial.println("2pressed");
  }
  if (digitalRead(12) == HIGH){
    input[arcount] = 3;
    arcount++;
    delay (200);
    Serial.println("3pressed");
  }



  int n;
  for (n = 0; n < 4; n = n + 1) {
    if(input[n] == storray [n] && arcount == 4){
      Serial.println("gooooood");
      arcount = 0;
      int i;
      for (i = 0; i < 4; i = i + 1) {
        Serial.print(input[i]);
      }
      Serial.println(" ");
      int j;
      for (j = 0; j < 4; j = j + 1) {
        Serial.print(storray[j]);
      }
      Serial.println(" ");
      return;
    }

    else {
      if(input[n] != storray [n] && arcount == 4){
        Serial.println("baaaaad");
        arcount = 0;

        int i;
        for (i = 0; i < 4; i = i + 1) {
          Serial.print(input[i]);
        }
        Serial.println(" ");
        int j;
        for (j = 0; j < 4; j = j + 1) {
          Serial.print(storray[j]);
        }
        Serial.println(" ");

        return;

      }
    }
  }
}

Here is the screenshot

}}}

Baaaad.
After the IDE's auto format

byte button[] = { 
  10, 11, 12 };

byte arcount = 0;

byte input[4];

byte storray[] = {
  1,2,3,2};


void setup() {
  // put your setup code here, to run once:
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(8, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  if (digitalRead(10) == HIGH){
    input[arcount] = 1;
    arcount++;
    delay (200);
    Serial.println("1pressed");
  }
  if (digitalRead(11) == HIGH){
    input[arcount] = 2;
    arcount++;
    delay (200);
    Serial.println("2pressed");
  }
  if (digitalRead(12) == HIGH){
    input[arcount] = 3;
    arcount++;
    delay (200);
    Serial.println("3pressed");
  }



  int n;
  for (n = 0; n < 4; n = n + 1) {
    if(input[n] == storray [n] && arcount == 4){
      Serial.println("gooooood");
      arcount = 0;
      int i;
      for (i = 0; i < 4; i = i + 1) {
        Serial.print(input[i]);
      }
      Serial.println(" ");
      int j;
      for (j = 0; j < 4; j = j + 1) {
        Serial.print(storray[j]);
      }
      Serial.println(" ");
      return;
    }

    else {
      if(input[n] != storray [n] && arcount == 4){
        Serial.println("baaaaad");
        arcount = 0;

        int i;
        for (i = 0; i < 4; i = i + 1) {
          Serial.print(input[i]);
        }
        Serial.println(" ");
        int j;
        for (j = 0; j < 4; j = j + 1) {
          Serial.print(storray[j]);
        }
        Serial.println(" ");

        return;

      }
    }
  }
}
  if (digitalRead(10) == HIGH){
    input[arcount] = 1;
    arcount++;
    delay (200);
    Serial.println("1pressed");
  }

You need to check that arcount is less than 4 BEFORE writing to the array.

If you put each { on a new line, and use Tools + Auto Format to make that code presentable, I might be able to make heads or tails of it. As it is, I can't.

Sorry for that, fixed;

As the 1st value for arcount is 0 (checked it by serial print) and it owervrites "byte input which is 0,0,0,0 in the beginning correctly with 4 values (i have been doing it with serial print of the array after each user entry)

With the braces where they belong:

  for (n = 0; n < 4; n = n + 1) 
  {
    if(input[n] == storray [n] && arcount == 4)
    {
      Serial.println("gooooood");
      arcount = 0;
      int i;
      for (i = 0; i < 4; i = i + 1)
      {
        Serial.print(input[i]);
      }
      Serial.println(" ");
      int j;
      for (j = 0; j < 4; j = j + 1)
      {
        Serial.print(storray[j]);
      }
      Serial.println(" ");
      return;
    }

On the first pass through loop, if input[ 0 ] matches storray[ 0 ], and the whole array has been populated, you print "gooooood", do a bunch of other stuff, and return.

You never actually compare [1], [2], or [3] of the arrays. Perhaps you want to separate the comparison part, setting a flag, from the printing/conclusion part.

Look at reply #51
This is how I did it.

Thank You HazardsMind, working as supposed to.
Here is the code:

byte button[] = { 
  10, 11, 12 };

byte arcount = 0;

byte input[4];

byte storray[] = {
  1,2,3,2};
boolean good;

void setup() {
  // put your setup code here, to run once:
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(8, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  if (digitalRead(10) == HIGH){
    input[arcount] = 1;
    arcount++;
    delay (200);
    Serial.println("1pressed");
  }
  if (digitalRead(11) == HIGH){
    input[arcount] = 2;
    arcount++;
    delay (200);
    Serial.println("2pressed");
  }
  if (digitalRead(12) == HIGH){
    input[arcount] = 3;
    arcount++;
    delay (200);
    Serial.println("3pressed");
  }
  if(arcount == 4){

    for(int count = 0; count < arcount; count++){
      if(input[count] == storray[count]) {
        good = true;
      }
      else {
        good = false;
        break;
      }
    }


    if(good) {
      Serial.println("gooooood");
      arcount = 0;
      int i;
      for (i = 0; i < 4; i = i + 1) 
      {
        Serial.print(input[i]);
      }
      Serial.println(" ");
      int j;
      for (j = 0; j < 4; j = j + 1) 
      {
        Serial.print(storray[j]);
      }
      Serial.println(" "); 
    }
    else {
      Serial.println("baaaaad");
      arcount = 0;

      int i;
      for (i = 0; i < 4; i = i + 1) {
        Serial.print(input[i]);
      }
      Serial.println(" ");
      int j;
      for (j = 0; j < 4; j = j + 1) {
        Serial.print(storray[j]);
      }
      Serial.println(" "); 
    }
  }
}