Re: itoa

From: Mike Stilson (mike@velgarian.sytes.net)
Date: 04/07/02


On Sun, Apr 07, 2002 at 07:05:56PM -0600, Brian wrote:
>Greetings,
>     Not being aware entirely of the prototype of itoa(), it's difficult to
>give you an exact answer.  It would help if you had quoted some code
>which utilized the function.  After some research, it appears Visual C++
>defines the function:
>
>char *itoa( int value, char *string, int radix );
Not sure on this one -----^^^^^^^

Something like this?

Without some surrounding code, I dunno what it wants for the 2nd
argument.  I'd guess it's going to be the same as the returned value,
but since I'm not sure I didn't bother with it.

--- semi-mailer code.  typed, compiled, tested twice, mailed. ---

#include <stdio.h>
#include <strings.h>
#include <stdlib.h>

/* enough room for base 62 or so */
const char *base_string = "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

char *itoa(int, int);

int main(int ac, char *av[])
{

        printf("Converted: ");
        printf("%s\n", itoa(atoi(av[1]), atoi(av[2])));
        exit(0);
}

char *itoa(int num, int radix)
{
        static char buf[4096];

        if(num>=radix) itoa(num/base, radix);
        sprintf(buf+strlen(buf), "%c", base_string[num%radix]);

        return(buf);
}
>Kras Kresh wrote:
>>
>> I need that function, [itoa] but my server doesn't seem to support it,

Must say I don't really see the need for it, sprintbits() handles
writing ascii pfiles nicely, and sprintf() and pals seem to take care of
the rest.

--
Under the DMCA, I'm allowed to use my computer and the internet to
design, discuss, and improve a thermonuclear weapon, but I can't
use it to watch a DVD while running Linux.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT