[Solved] C++ how to to convert integers and longs to char arrays


Converted to decimal ascii string (not nul-terminated, buffer ‘large enough’) :

size_t ultoa (char *buf, unsigned long u)
{
    char *bptr = buf, *df, *dr;

    do *bptr = ('0') + (char) (u % 10);
    while ((u /= 10) != 0);

    for (df = buf, dr = bptr - 1; df < dr; )
    {
        char di = *df, dj = *dr;
        *df++ = dj, *dr-- = di; // (exchange)
    }

    return ((size_t) (bptr - buf)); // (digits)
}

solved C++ how to to convert integers and longs to char arrays