I NEED HELP WITH THIS C PROGRAMMING QUESTION
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[])
{
}
011 Entet word of poate bet or 05 05 ato: 5105, 051 10 25 my_tot 505, X5 10 25 Enter a word of positive niomber or quit* 12 12 atoli 12 2014, c) 24 my_tot 12 (014.) 24 Enterwondo positive number or quit: 012 12 1014.24 wy_atoit 10 2012, OXA) 20 100 Enter word opsitive number or itt: x2 0X12 atott 0 0.0 nyatoit 1022. 0X121 36 Ente word of positive number or quit: 123 223 atoi 123 (017), 0X7B) 24 15120 my_ato 123 (0173, 073) 24 15120 Enter a word of positive number or quitt: 0123 Ato: 123 0173, 0X78) 246 ay_atos 83 0123, OXS >> Enter a word of poattive number or 'uit 164 164 (0244, OXA) my_tot 164 (0246. OKM 320 2695 Enter a woxd of positive number of at 0164 0164 Atot 164 (0246. OXA my to: 116 0164 074) 1356 Enter a word of positive number of mit 0164 0 0,0) 0 D wy_atoil 356 0544, OX164) 912 126736 Enter word of positive number of it. OXIB OX 10,0) 0 my_atot 27 (033, 154 730 Enter word of positive number one x2 ti 0.0.0 D 0 nyatos 42 1057, 04 364 atos Antes word of positive number or it0224 atott 0 0.0 0 wy_atoit 1057 X 14 2200 Enter word of positive number or quit: Oxen OKFI acoin 0 0 ny_atoit 251 037), OXES) SO Enter a word of positive number or quit Ted 128 1. Problem A. Character array, char, number systems (35pts) 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 "0x18" or "Oxib", it returns decimal value 27. (atoi will return 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 0x and contains digits 0-9 and letters 'A' 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 callatoilinmy_atoi(). . In my_atoi (), you also should not call other functions declared in
, such as atoll), atof(), strtolo, strtoul(). Inmy_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 my_atoi: 4 (04, 0X4) Enter a word of positive number or 'quit': 5 5 atoi: 5 (05, 0X5) my_atoi: 5 (05, 0X5) 10 16 16 8 10 25 25