Return to Snippet

Revision: 1861
at November 15, 2006 02:29 by priyanhere


Initial Code
/* ========================================================================== */
/*                                                                            */
/*   itoa.h                                                                   */
/*   (c) 2006 Priyadarsan                                                     */
/*                                                                            */
/*   a program to convert integer to string                                   */
/*   (Original Code: http://www.freebookzone.com/others/itoa.h)               */
/*    Ex. usage file available at http://www.freebookzone.com/others/itoa.c   */
/*                                                                            */
/* ========================================================================== */

char* itoa (int n){
  int i=0,j;
  char* s;
  char* u;

  s= (char*) malloc(17);
  u= (char*) malloc(17);
  
  do{
    s[i++]=(char)( n%10+48 );
    n-=n%10;
  }
  while((n/=10)>0);
  for (j=0;j<i;j++)
  u[i-1-j]=s[j];

  u[j]='\0';
  return u;
}

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

Initial Description

                                

Initial Title
(Integer to String ) itoa

Initial Tags
c

Initial Language
C++