Completely emptying an array

Hi all.
I need help in emptying an array completely.
I searched and saw that the usual way to go was overwriting all the elements of the array with zeros but this doesn't help in my case.
I need it to be completely empty as at when declared.

Fully explained: I'm working on changing a password. But the old password needs to be entered and verified. It is entered into an array (which was declared with just size but no elements) and compared with the array containing the password that is currently being used. If the old password is correct, it moves to the next step of accepting a new password. If not, it displays a message that the password is not accepted.

When doing this the first time, it works probably because the array was just filled. But on subsequent trials, it jumps straight to tell you that the password isn't accepted. I think this is because the previous elements still exist in the array. If I were to overwrite the contents with zeros (which I did using the memset function), it'll still do the same because it sees the zeros as the old password which doesn't correlate with the running password.

Is the password stored as text? In that case, overwriting the first element with '\0' or overwriting the complete array should be sufficient.
If it's stored as binary numbers, overwriting will not work.

Note that an array is initialised with zeroes if it's declared as a global variable.

byte array[20];

void setup()
{
}

void loop()
{
}

The variable array in above example contains only zeroes.

I suggest that you share your code so we can see what you're doing.

An array is never empty
It will always contain something, even if newly declared

Global arrays are initialised to all zeroes if no specific values are given and local arrays are initialised to whatever is already in the memory allocated to them

If the password is held as an array of chars then are you properly terminating it ?

Please post the full sketch that illustrates the problem that you are having

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.