(Integer to String ) itoa


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /* ========================================================================== */
  2. /* */
  3. /* itoa.h */
  4. /* (c) 2006 Priyadarsan */
  5. /* */
  6. /* a program to convert integer to string */
  7. /* (Original Code: http://www.freebookzone.com/others/itoa.h) */
  8. /* Ex. usage file available at http://www.freebookzone.com/others/itoa.c */
  9. /* */
  10. /* ========================================================================== */
  11.  
  12. char* itoa (int n){
  13. int i=0,j;
  14. char* s;
  15. char* u;
  16.  
  17. s= (char*) malloc(17);
  18. u= (char*) malloc(17);
  19.  
  20. do{
  21. s[i++]=(char)( n%10+48 );
  22. n-=n%10;
  23. }
  24. while((n/=10)>0);
  25. for (j=0;j<i;j++)
  26. u[i-1-j]=s[j];
  27.  
  28. u[j]='\0';
  29. return u;
  30. }

URL: http://www.freebookzone.com/others/itoa.h

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.