Question: INNEED HELP ASAP WITH C PROGRAMMING CLEAR PICUTRS this is to start you off #include //more header files and declarations as needed #define SIZE 10
INNEED HELP ASAP WITH C PROGRAMMING CLEAR PICUTRS this is to start you off
#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 Ox 18" or "ox1b", it returns decimal value 27. (atoi will return o for both). 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 'Al-'F' and 'a' "E' only. For each input, the program first prints it as a string, and then callatoi 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_atoio. In myatoi . you also should not call other functions declared in , such as atolt), atof(), strtoli), strtoul(). In my_ato: 0). you also should not call library functions declared in cstdio.h>, such as sncanf(), facanf(). 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 gec. . 4 16 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 atoi: 4 (04, 0X4) my_atoi: 4 (04, 0X4) 16 Enter a word of positive number or quit': 5 5 atoi: 5 (05, 0X50 10 25 my_atoi: 5 (05, 0x5) 10 8 8 25 2 Enter a word of positive number or 'quit': 05 05 atoi: 5 (05, 0X5) 10 25 my_atoi: 5 (05, 0X5) 10 25 Enter a word of positive number or quit': 12 12 atoi: 12 (014, 0XC) 24 my_atoi: 12 (014, OXC) 24 144 Enter a word of positive number or quato: 012 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 Ox12 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 OO Enter a word of positive number or 'quitt: oxi OX1B atoi: 0(0, 0) 0 0 my_atoi: 27 (033, 0x1B) 54 729 Enter a word of positive number or 'quit': 0x27 OX2E atoi: 0(0, 0) 0 my_atoi: 47 (057, 0X2F) 94 2209 0 3 Enter a word of positive number or 'quit: 0x2f Ox2 atoi 0(0, 0) 0 0 my_atoi: 47 (057, 0X2F) 94 2209 Enter a word of positive number or 'quit: OxfB OXES atos: 0(0,0) 0 0 my_atoi: 251 (0373, OXFB) 502 63001 Enter a word of positive number or 'quit': quit red 128