[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: where the hell is itoa()?



On Sat, Jul 14, 2001 at 10:57:04PM +0300, Ariel Biener wrote:
> On Sat, 14 Jul 2001, Shaul Karl wrote:
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main()
> {
> 
>     char *mychar;
>     int a=99999;         /* Just some random number */
> 
>     mychar=(char *)calloc(1, sizeof(int));

Just allocate a long enough string buffer -- char[32] should do it even 
for long long. sizeof(int) will never be enough.

>     sprintf(mychar, "%d%c", a, '\0');

You don't need to explicitly write the null character in sprintf.

>     return 1;
> }

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il