Ok, well i have been trying to write a recursive version of itoa, this is what i came up with.
void itoa(int n, char s[])
{
static int i = 0;
if(n / 10 != 0)
itoa(n/10, s);
else if(n < 0)
i = 1; /* s[0] is allready taken by - sign */
else
i = 0; /* reset i to 0 */
if(n < 0) {
s[0] = '-';
}
s[i++] = abs(n % 10) + '0';
s[i] = '\0';
}
But i dont think its so good, it uses a static variable and probably isnt as fast as it should be - O(n), what i want to achieve. Could anyone show me a better way, and i also think that static variable isnt neccesary, but im not preety sure how to avoid it... if i want to avoid static ill need to break it into 2 functions then?