There are a number of ways to do what you describe. Here are two of them
Method 1
Initialise a target variable to zero
Read a character from the keypad when it becomes available
If the character is between '0' and '9' subtract '0' from it
Multiply the target by 10 and add the number from the step above
Do that 4 times and you have a 4 digit number in the target variable
Method 2
Declare a char array of 5 characters
Declare an index variable and initialise it to zero
Read a character from the keypad when it becomes available
If the character is between '0' and '9' save it to the array at the current index position, increment the index and put '0' in the array at that position to terminate the string
Do that 4 times and save 4 characters and you have a C string containing 4 characters
Use the atoi() function to convert the string to an int