Sunday, August 26, 2012

Exercise 4-12

My solution for Exercise 4-12
THE C PROGRAMMING LANGUAGE, 2nd ed.
Kernighan and Ritchie

char *myitoa2(int n, char *s)
{
    int sign;

    if ((sign = n) < 0) {
        n = -n;
        *s++ = '-';
    }
    if (n / 10) {
        s = myitoa2(n / 10, s);
    }
    *s++ =  n % 10 + '0';
    *s = '\0';
    return s;
}

-unkokusei

1 comment: