Implement the itoa function as efficiently as you can.. How do you handle errors if you had to
void itoa(char *a ,int n) { int sign; if((sign = n) < 0) n = -n; char *b = a; /* pointer to hold the initial address */ printf("the address od the array before starting is: %x\n",a); do { *a = n % 10 + '0' ; a++; }while((n /= 10 ) > 0); if(sign < 0) { *a = '-'; a++; } printf("the address after reverse is:%x\n",a);
reverse(b); }
void reverse(char *s) { int t; char *a; a = s + (strlen(s)-1); printf("the address is :%x\n",a); for( ; s < a ; s++,a--) { t = *s; *s = *a; *a = t; } }
Implement the itoa function
void itoa(char *a ,int n)
{
int sign;
if((sign = n) < 0)
n = -n;
char *b = a; /* pointer to hold the initial address */
printf("the address od the array before starting is: %x\n",a);
do
{
*a = n % 10 + '0' ;
a++;
}while((n /= 10 ) > 0);
if(sign < 0)
{
*a = '-';
a++;
}
printf("the address after reverse is:%x\n",a);
reverse(b);
}
void reverse(char *s)
{
int t;
char *a;
a = s + (strlen(s)-1);
printf("the address is :%x\n",a);
for( ; s < a ; s++,a--)
{
t = *s;
*s = *a;
*a = t;
}
}