itoa'd you so?

Charles Curley charlescurley at
Fri Sep 21 18:37:45 MDT 2007

On Fri, Sep 21, 2007 at 04:11:44PM -0600, Dave Smith wrote:
> Charles Curley wrote:
> >Ah, good. Did you finally get around to looking at the solution I
> >posted to this thread two days ago?
> >  

> It also crashes at random points (sometimes after 6700 invocations,
> sometimes after 5001, sometimes after 8105, etc) when run in a for
> loop.

With the version of the itoa function I posted earlier, I'm not seeing
it crash. I re-wrote the test frame as follows:


main (int argc, char *argv[])
    char buffer[23];
    char test[23];
    int i;
    int start = -1;
    int stop = 10000000;

/*    buffer[0] = 0;              /* Force buffer to hold a string of
                                 * length 0. Likely another trick the
                                 * examiner wanted. */

    base = 10;

    printf ("%s, a program to exercise a subroutine to convert an int to a string.\n",
    printf ("Going from %i to %i.\n", start, stop);

/*     printf ("0x%x converts to a string as %s.\n", test, itoa (test, buffer)); */

    for (i=start; i != stop ; i++) {
/*         printf ("i = %i\n", i); */
        buffer[0] = 0;
        sprintf (test, "%i", i);
        itoa (i, buffer);
        if (strcmp (buffer, test)) {
            printf ("Output differs from expected. Test: %s. Buffer: %s\n",
                    test, buffer);

(I think it is safe to assume that sprintf works correctly....)

and got:

[ccurley at dragon itoa]$ time ./itoa 
./itoa, a program to exercise a subroutine to convert an int to a string.
Going from -1 to 10000000.

real    0m6.341s
user    0m6.241s
sys     0m0.013s
[ccurley at dragon itoa]$ 

on a processor like so:

model name      : Intel(R) Pentium(R) M processor 1.60GHz
stepping        : 6
cpu MHz         : 1598.674
cache size      : 2048 KB

Have we beaten this thing into the ground yet?


Charles Curley                  /"\    ASCII Ribbon Campaign
Looking for fine software       \ /    Respect for open standards
and/or writing?                  X     No HTML/RTF in email    / \    No M$ Word docs in email

Key fingerprint = CE5C 6645 A45A 64E4 94C0  809C FFF6 4C48 4ECD DFDB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : 

More information about the PLUG mailing list