title: itoa function does not work for single digit integers
body: <p>I have a custom itoa function that works for integers 10 and greater, but for some reason it returns nothing if the integer passed is a single digit. I can't seem to figure out why that is. </p>
  
  <p>When I print the array after it has been reversed by simply accessing <code>array[0]</code> and <code>array[1]</code>, I see that a null and that single digit is printed fine, but there is some weird trailing character after the single digit. This only happens for single digits.
  for example <code>(blank)7e</code> or <code>(blank)4r</code></p>
  
  <p>The function:</p>
  
  <pre><code> char* customitoa(int number, char * array, int base){
  
  array[0] = '\0';
  
      int quotient = number, i = 1;   
  
  /* stores integers as chars into array backwards */ 
  
      while(quotient != 0){
              int temp, length = 1;
              temp = quotient % base;
  
              length++;
              array = realloc(array, (length)*sizeof(char));
  
              if (temp &lt;= 9){
                  array[i++] = (char)(((int)'0')+temp);
                  } else {
                  array[i++] =  (char)(temp + ('A' - 10));
                  }
              quotient = quotient / base;
  
          }
  
  /* reverse array*/ 
  int j; int k;
      k = 0;
      j = i - 1;
      char temp;
  /* - different swap functions based on odd or even sized integers */
      if( (j%2) == 1){
  
          while((k &lt;= ((j/2)+1))){ 
              temp = array[k];
              array[k] = array[j];
              array[j] = temp;
              k = k+1;
              j = j - 1;
              }
          } else {
              while(k &lt;= (((j)/2))){ 
                  temp = array[k];
                  array[k] = array[j];
                  array[j] = temp;
                  k = k+1;
                  j = j - 1;
              }
          }
  
      return array;
      }
  </code></pre>
  
  <p>The function is called in this context:</p>
  
  <pre><code>char *array;
  array = malloc(length*sizeof(char));
  
  array = myitoa(number, array, base);
  
  printf("%s", array);
  
  free(array);
  </code></pre>