How to compare two integer passwords using array

UKHeliBob:
To get the user input into an integer you need to

read they key

if it is between '0' and '9'
  subtract '0' to gtet the value of the number entered
  multiply the target integer variable by 10 and add the result of the subtraction
end if
do this 4 times if the passcode is a 4 digit integer




To get the user input into an array of chars you need to


read the key
if it is between '0' and '9'
  put it into an array of chars at the current position
  increment the current position variable
  (optional) put '\0' in the current postion if you need the array to be a C string
end if
do this 4 times if the passcode is a 4 digit integer

Something like this?:

int key=kpd.getKey();
if(key)
{
 key=key-0;
 key2=(key2*10)+key;
}

How do I do this 4 times?