RE: [Dev-C++] itoa - atoi : another implementation
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-04-02 17:45:17
|
The most common is one of the following declarations:
void itoa(int num, char *buf, int base);
void itoa(int num, char *buf);
Neither have problem with lost memory, and both are reentrant.
The first form is always useful, since it allows adjustable number base,
i.e. binary, trinary, ...
The second form is only needed in embedded programs, since it requires
less RTL support than the big-big-big sprintf() - note that sprintf()
doesn't know whet additional support that is required, so it has code for
left-adjust, right-adjust, int, long, signed, unsigned, string, pointer,
float, double, ...
/Per W
On Wed, 2 Apr 2003, Ioannis Vranos wrote:
> My own contribution to this entirely unneded function:
>
> #include <stddef.h>
> #include <stdlib.h>
> #include <stdio.h>
>
>
> char *itoa(int i)
> {
> size_t Length;
> char *p;
> int temp=i;
>
> for(Length=0; temp/=10; Length++)
> ;
>
> p=malloc((Length+1)*sizeof(i));
>
> sprintf(p, "%d", i);
>
> return p;
> }
>
>
>
> Why would anyone need itoa()? With sprinf() one can easily do the
> conversion.
>
>
> sprintf(s,"%d", i);
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL: http://run.to/noicys
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|