Implementation of itoa int get_digits (int num)
{
   if(num &lt; 10)
      return 1;

   if(num &lt; 100)
      return 2;

    if(num &lt; 1000)
      return 3;

    if(num &lt; 10000)
      return 4;

    if(num &lt; 100000)
      return 5;

    if(num &lt; 1000000)
      return 6;

    if(num &lt; 10000000)
      return 7;

    if(num &lt; 100000000)
      return 8;

    if(num &lt; 1000000000)
      return 9;

    return 10; /* num &gt; 1000000000 */
}

char *itoa (int n)
{
    static char temp[10]; // MN that can be replaced by some def?
    int nDigits = 0;
    int i = 0;
 
    if(n == 0)
    {
        temp[0] = '0';
        temp[1] = '\0';
 
       return temp; // or just return &quot;0&quot;; ?
    }
 
    nDigits = get_digits(n); // fast function to count digits..
 
    temp[nDigits] = '\0'; // ..needed just here
 

   for(i = n; i &gt;= 1; i /= 10) // whole method stinks
    {
        temp[--nDigits] = ((i % 10) + '0'); // modulo is quite slow
    }
 
    return temp;
}

This is my implementation of the infamous function itoa(), which isn't available everywhere and more importantly not available in my environment. Generally, the implementation of this function is ought to be different anyway. Performance and memory optimization is important.
This function converts an integer to a string. The function owns the reference to the returned string, which is statically allocated and the caller is responsible to make a copy of the returned string if he plans on changing it or preserving it across subsequent calls.
The code almost works.
To make it work in all cases, test the program with Valgrind, which detects undefined behavior because of invalid memory access. This will prove that the buffer needs to be 11 bytes long, not only 10.
What about platforms where int has 64 bits instead of just 32? For these you need a larger buffer. Until then, you should use a compile-time assertion (static_assert) to ensure this implicit assumption.
What about negative numbers? -6 is a valid integer as well, and it should be converted appropriately.
If this function is the bottleneck of your whole program because it is too slow, have a look at how the Go programming language converts integers to strings. It's in the strconv package and uses lots of nice tricks to cut down the number of integer divisions, since that's the most expensive machine instruction in your code.
You can get rid of the get_digits function if you have the end of the string at a fixed address. Start with:
char *p = buf + sizeof buf - 1;
*p = '\0';

and then continue to fill the buffer from right to left by doing *(--p) = '0' + digit. At the end just return p, which will point to the first digit.
The return type should be const char * instead of char * since the caller is not supposed to do anything to the buffer.