pleasc 3. You are to write a subroutine named \"kevpad4x4 integer\" that will us
ID: 3589646 • Letter: P
Question
pleasc 3. You are to write a subroutine named "kevpad4x4 integer" that will use the keypad to input mulsi-digit integers. (You may use any of the functions from keypad4x4.h as building blocks) When call subroutine should read characters from the 4x4 kevpad. If the characters are in the range 0he new digit should be added to the number. If the first key pressed is, the number should be negative. If the .#" key is pressed it indicates the end of input and the resulting integer should be returned. If any other key is pressed, it shouid be ignored.Explanation / 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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.