oops ... I did that too quickly without thinking.

above inserts leading zeroes!

should insert the following before the main loop:

Code:
     while( i > n ) i /= 10;
i.e.

Code:
 int inttostr( char *s, int n )
{
        unsigned int i = 1000000000;

        if( ((signed)n) < 0 ) {
                *s++ = '-';
                n = -n;
        }

        while( i > n ) i /= 10;

        do {
                *s++ = '0' + (n-n%i)/i%10;
        } while( i /= 10 );

        *s = 0;

        return n;
}
this is actually considerably faster

Code:
real	0m0.112s
user	0m0.104s
sys	0m0.004s