# How to store an array.

Status
Not open for further replies.

#### caramelz

##### Junior Member level 2
guys i need some help. i wan to store an password inside the keypad so when correct password is typed in the keypad, the programme will jump to the next selection, if not it will loop back. help please

#### pratzz

##### Member level 5
just predefine your password length and keep them storing in contiguous memory location in an array.
like suppose you have predefined password in char array pass[4]={'1','2','3','4'}.
then when you take input from user put it in other array let it be char user[length] and take the input in it.
then compare each element of both arrays i.e. use
Code:
for(i=0;i<pass_length;i++)
{if(pass[i]!=user[i])
flag=1;
break;
}
now after this loop check if flag is 0 if it is then password is correct.

Last edited:

#### caramelz

##### Junior Member level 2
i did a DO loop for 3 times, so th;e keypad only can key in 3 numbers. so do i have to come out with a StoreArray[3]={'1','2','3'};
Code:
if i name the input as keyPad

for(i=0;i<StoreArray_length;i++)
Code:
flag=1;
break;
Code:

is it like that ? sorry i'm a beginner in this. and btw the code u gave work for C++ right\?

#### pratzz

##### Member level 5
first of all to maintaint clarity always post code in code tags(# sign given on top).
the code is right although i forgot to put } after break which i have corrected nowand it will work for both c and c++.

Status
Not open for further replies.