|
From: Ioannis V. <iv...@em...> - 2003-04-02 21:23:37
|
^%^%%^*@#@# a bug had survived. The good & last:
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
char *itoa(int i)
{
size_t Length;
char *p;
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;
}
temp*=sign;
for(Length=0; temp/=10; Length++)
;
p=malloc(Length+1+!(sign==1));
if(!p)
return NULL;
sprintf(p, "%d", i);
return p;
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|