appendItem to an Array Function?

Ok, let me break this down. So I am creating a tft passcode lock with a 3x3 array of buttons. The password is stored in an array, let's say

int password[] = {1,2,3,4,5};

And now

int guess[] = {};

I want to be able to add an item to the array guess whenever a button is pressed. This is what I have to check if the password is correct:

if(sizeof(guess)==sizeof(password)){
      if(guess==password){
        Serial.println("Access Granted");
      }
      guess == 0;
    }

But there is no such arduino function that adds a value to the array. I can't use a for loop and replace values with "i" because guess would always be 5 characters long and there is no way of pausing the loop if no value is pressed.

Get yourself a copy of the library manual.

23.11.3.14 char * strcat ( char * dest, const char * src )

Concatenate two strings.

The strcat() function appends the src string to the dest string overwriting the '\0' character at the end of dest, and then adds a terminating '\0' character. The strings may not overlap, and the dest string must have enough space for the result.

Returns

The strcat() function returns a pointer to the resulting string dest.

Thanks! I just did this:

String password = "12345";
String guess = "";

And then I concatenate

guess += (number pressed);

Now you're using String instead of char array. There are plenty of comments advising against using String variables with a low resourced microcontroller such as the 328P.

Use zero terminated arrays of chars, aka strings

At some point the array will need to hold x characters so just declare it that big to start with.

And now

int guess[] = {};

Since you didn't provide an explicit size, the compiler counted the number of initializers you provided, and came up with 0. So, that statement is EXACTLY the same as

int guess[0];

which anyone can see creates a completely useless array.