#include // Precondition: The array has to be big enough to hold the // number int itoa (int i, char *str) { int sign; int digit; int pos = 0; // Question: Is it actually an integer? It has to be. The // C compiler will complain if we try to give it soemthing // else. // Check the sign and make it positive if ((sign = i) < 0) i = -i; do { // Grab the rightmost digit digit = i % 10; // Shove it into the string str[pos++] = digit + '0'; // Drop the digit and move on to the next position i = i / 10; } while (i > 0); // If it's negative, add the sign if (sign < 0) str[pos++] = '-' // End the string str[pos] = '\0'; // It's backwards, so fix it reverse (str); return 1; } // itoa int main () { char str[100]; itoa (3, str); return 0; } // main