Question: myatoi.c #include //more header files and declarations as needed #define SIZE 10 int main(int argc, char *argv[]){ int a,b; char arr [SIZE]; printf(Enter a word

 myatoi.c #include //more header files and declarations as needed #define SIZE

10 int main(int argc, char *argv[]){ int a,b; char arr [SIZE]; printf("Enter

a word of positive number or 'quit': " ); scanf("%s", arr); while(

myatoi.c

#include  //more header files and declarations as needed #define SIZE 10 int main(int argc, char *argv[]){ 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, %#X)\t%d\t%d ", a,a,a, a*2, a*a); b = my_atoi(arr); printf("my_atoi: %d (%#o, %#X)\t%d\t%d ", b,b,b, b*2, b*b); .... } return 0; } /* convert an array of digit characters into a decimal int. Input is either a valid Decimal or Octal or Hex integer literal. */ int my_atoi (char c[]) { }

1.1 Specification As we all know, Standard library defines a library function atoi. This function converts an array of digit characters, which represents a Decimal integer literal, into the corresponding decimal integer. atoi does not handle Oct and Hex literals correctly. Here you are going to implement an extended version of atoi called my_atoi, which does the same conversion for Decimal literals but also converts Octal (base 8) and Hex (base 16) integer literals. For example, given char array "012" the function returns integer 10 whereas given char array "0x1B" or "OX1b", it returns decimal value 27. (atoi will return o for both). C 1.2 Implementation Download the file myatoi.c to start off. Eeach input is assumed to be a valid Decimal integer literal such as "125" or a valid Octal integer literal which starts with O and contains digit 1-7, such as "0125", or a valid Hex literal which starts with ox or Ox. and contains digits 0-9 and letters 'A''F' and 'a'. 'f' only. For each input, the program first prints it as a string, and then call atoi and my_atoi to convert it, and then outputs its numerical value in Decimal, Octal, and Hex, followed by double the value and square of the value (implemented for you). The program keeps on reading from the user until quit is entered. . Note: 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(). You are free to use other library functions. Remember that if you use math library functions and you compile your program in the lab environment, you need to use -Im flag of gcc. 1.3 Sample Inputs/Outputs (note that atoi doesn't handle Octal and Hex literals correctly). red 127 % a.out Enter a word of positive number or 'quit': 4 4 atoi: 4 (04, 0X4) 8 16 my_atoi: 4 (04, 0X4) 8 16 Enter a word of positive number or 'quit': 5 5 atoi: 5 (05, 0X5) 10 25 my_atoi: 5 (05, 0x5) 10 25 Enter a word of positive number or 'quit': 05 05 atoi: 5 (05, 0X5) 10 25 my_atoi: 5 (05, 085) 10 25 Enter a word of positive number or 'quit': 12 12 atoi: 12 (014, OXC) 24 144 my_atoi: 12 (014, OXC) 24 144 Enter a word of positive number or quit': 012 012 atoi: 12 (014, OXC) 24 144 my_atoi: 10 (012, OXA) 20 100 Enter a word of positive number or 'quit': 0X12 0X12 atoi: 0 (0, 0) 0 0 my_atoi: 18 (022, 0X12) 36 324 Enter a word of positive number or 'quit': 123 123 atoi: 123 (0173, 0X7B) 246 15129 my_atoi: 123 (0173, 0X7B) 246 15129 Enter a word of positive number or 'quit': 0123 0123 atoi: 123 (0173, 0X7B) 246 15129 my_atoi: 83 (0123, 0X53) 166 6889 Enter a word of positive number or 'quit': 164 164 atoi: 164 (0244, OXA4) 328 26896 my_atoi: 164 (0244, OXA4) 328 26896 Enter a word of positive number or 'quit': 0164 0164 atoi: 164 (0244, OXA4) 328 26896 my_atoi: 116 (0164, 0X74) 232 13456 Enter a word of positive number or 'quit': 0x164 Ox164 atoi: 0 (0, 0) 0 0 my_atoi: 356 (0544, 0X164) 712 126736 Enter a word of positive number or 'quit': 0X1B OX1B atoi: 0 (0, 0) 0 0 my_atoi: 27 (033, 0X1B) 54 729 Enter a word of positive number or 'quit': 0X2F OX2F atoi: 0 (0, 0) 0 0 my_atoi: 47 (057, 0X2F) 94 2209 Enter a word of positive number or 'quit': 0x2f Ox2f atoi: 0 (0, 0) 0 0 my_atoi: 47 (057, 0X2F) 94 2209 Enter a word of positive number or 'quit': OxfB OXFB atoi: 0 (0, 0) 0 0 my_atoi: 251 (0373, OXFB) 502 63001 Enter a word of positive number or 'quit': red 128 % quit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!