Question: Extend the program you developed above, so that myatio () function can convert any base of 2010. (The library function atoi can only handle decimal
Extend the program you developed above, so that myatio () function can convert any base of 2010. (The library function atoi can only handle decimal literals correctly.) This version of my_atoi takes two arguments: an integer literal and a base. Assume the input string is a valid integer literal of the specified base. For example, if the base is 2, the literal only contains and 1. If the base is 5, the literals contains digit 0~4. Note: Use scanf("%s %d", ...) to read in a string followed by an integer of 2-10. The program terminates when use enter quit followed by any integer. Apparently, you should not call atoi() in my_atoi (). In my_atoi (), you also should not call other functions declared in , such as atol(), atof(), strtol(), strtoul(). In my_atoi (), you also should not call library functions declared in , such as sscanf(), fscanf(). . . Sample Inputs/Outputs: red 127 % a.out Enter a word of positive number and base, or 'quit': 37 10 37 my_atoi: 37 (045, 0X25) 74 1369 Enter a word of positive number and base, or 'quit': 37 8 37 my_atoi: 31 (037, 0X1F) 62 961 Enter a word of positive number and base, or 'quit': 122 4 122 my_atoi: 26 (032, 0X1A) 52 676 Enter a word of positive number and base, or 'quit': 122 5 122 my_atoi: 37 (045, 0X25) 74 1369 Enter a word of positive number and base, or 'quit': 122 7 122 my_atoi: 65 (0101, 0X41) 130 4225 Enter a word of positive number and base, or 'quit': 1101 2 1101 my_atoi: 13 (015, OXD) 26 169 Enter a word of positive number and base, or 'quit': 1001100 2 1001100 my_atoi: 76 (0114, 0X4C) 152 5776 Enter a word of positive number and base, or 'quit': 345 6 345 my_atoi: 137 (0211, 0X89) 274 18769 458 Enter a word of positive number and base, or 'quit': 345 8 345 my_atoi: 229 (0345, OXE5) 52441 Enter a word of positive number and base, or 'quit': 3214 5 3214 my_atoi: 434 (0662, 0X1B2) 868 188356 Enter a word of positive number and base, or 'quit': 11111111 2 11111111 my_atoi: 255 (0377, OXFF) 510 65025 Enter a word of positive number and base, or 'quit': quit 4 red 128 % #include #include // for atoi #define SIZE 10 int main() { int a,b; char arr [SIZE]; printf("Enter a word of positive number or 'quit:" ); scanf("%s", arr); while( ) { printf("%s ", arr); a = atoi(arr); printf("atoi: %d (#o, )\t%d\t%d ", a, a, a, a*2, ata); b = my_atoi(arr); printf("my_atoi: %d (#0, #x) \t%d\t%d ", b, b, b, b*2, b*b); } return 0; } /* convert an array of digit characters into a decimal int */ /* textbook did scan from left to right. Here you should scan from right to left. This is a little complicated but more straightforward (IMHO) */ int my_atoi (char c[]) }