1. /*
  2.  * Function: itoa
  3.  * Objective: Convert int (i) to char* by adding 0x30 (decimal 48) to each digit and terminate the string.
  4.  * Synopsis: char* itoa(int i);
  5.  * Example(s): itoa(123456789);
  6.  * - returns "123456789"
  7.  * Notes: We sacrifice memory for speed by using the z variable
  8.  */
  9. char* itoa(int i)
  10. {
  11. if(i==0) return "0";
  12. int w,x,y,z;
  13. for(x=0;pow(10,x)<=i;x++) ;
  14. char* string=malloc((sizeof(char)*x));
  15. y=x-1;
  16. for(x-=1;x>=0;x--)
  17. {
  18. z=pow(10,x);
  19. if(x<0) break;
  20. w=(i/z);
  21. i=i-(z*w);
  22. string[y-x]=(char)(w+'\x30');
  23. }
  24. return string;
  25. }