Please be done in C. ou are to write a subroutine named \"keypad4x4 integer\" th
ID: 3589596 • Letter: P
Question
Please be done in C.
ou are to write a subroutine named "keypad4x4 integer" that will use the keypad to input multi-digit egers. (You may use any of the functions from keypad4x4.h as building blocks) When called, the subroutine should read characters from the 4x4 keypad. If the characters are in the range-o *", the number shou ' - 9", the ld be new digit should be added to the number. If the first key pressed is negative. If the .#'key is pres returned. If any other key is pressed, it should be ignored. sed, it indicates the end of input and the resulting integer should beExplanation / Answer
// C code
//The given code below is the function definition for the requirement stated in the question.
//We have used the return type int because we will be returning the int value to the called function.
int keypad4*4_float(char str[1005])
{
char str_final[1005]; // We have defined the final string to store the output value.
int length=0,i=0,j=0;
int result=0;
length= strlen(str); // To determine the length of the string for looping purpose.
// Here we check for all the possible values and append the required character to the final string.
for(i=0;i<length;i++)
{
if(str[i]=='0'|| str[i]=='1'|| str[i]=='2'|| str[i]=='4'|| str[i]='5'|| str[i]='6'|| str[i]=='7'|| str[i]=='8'|| str[i]=='9')
str_final[j++]=str[i];
else if(str[i]=='#') // end of input return
break;
else if(str[i]=='*') // negative number
str_final[j++]='-';
}
result=atoi(str_final); //atoi() function used for the conversion from string to int
// return the resultant integer
return result;
}