How to clear an array

Hello everyone !

I'm currently building a simple system that let's you use an IR remote to type a password.
I store the password numbers inside an array.
The problem is that I dont know how to initialize the array so that in the next attempt to type the password, the array will be initialized, meaning doesn't hold any data in it.
Can someone help me by telling me how to initialize and clear the array ?

Thank you very much :slight_smile:

The problem is that I dont know how to initialize the array so that in the next attempt to type the password, the array will be initialized, meaning doesn't hold any data in it.
Can someone help me by telling me how to initialize and clear the array ?

You could use the memset() function. But, you don't need to. You know, at any given time, where the valid data in the array starts, and where it ends. Just ignore the data outside that range.

What do you mean by "clear the array" ?
It is trivial to use a for loop to fill it with any value that you like. What type of data is held in the array ?

What is your code? Maybe is easiest to show you it in the real program. You only have to hat a for loop where you give a zero to each element of the array.

I understand, i fixed the problem :slight_smile: haha I was a little cunfused. Thank you.

UKHeliBob:
What do you mean by "clear the array" ?
It is trivial to use a for loop to fill it with any value that you like. What type of data is held in the array ?

It really depends what you're using to detect that the correct password has been entered. If you're using something like strcmp, then you could simply put a 0 terminator in the first char of your array ( pwd[0]=0; ). It would then appear to be an empty string.

This would also necessitate that you terminate your string when the user keys in their attempt. (pwd[index]=key; pwd[index+1]=0;) Otherwise they may gain access by simply getting lucky on the first character.