|
From: Ioannis V. <iv...@em...> - 2003-04-02 22:36:14
|
I decided to take the subject a bit more seriuosly and ended with the
following:
#include <stdlib.h>
#include <stdio.h>
char *iitoa(int i)
{
long Length, j;
char *p;
char numchars[]="0123456789";
int temp=i;
int sign=temp<0?-1:1;
if(!temp)
{
p=malloc(2);
if(!p)
return NULL;
p[0]='0', p[1]=0;
return p;
}
for(Length=1; temp/=10; Length++)
;
p=malloc(Length+=1+(sign==-1));
if(!p)
return NULL;
if(sign==-1)
p[0]='-';
p[Length-1]=0;
for(temp=i*sign, j=Length-2; j>=(sign==1?0:1); j--)
{
p[j]=numchars[temp%10];
temp/=10;
}
return p;
}
It doesn't convert to any other number base, it produces only in decimal.
My apologies for the many emails.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|