title: Returning a string to a variable length character array
body: <p>I have a program that reverses a string from an input of a variable length character array. The function returns a variable length character array and is printed. When I print the output, I do get the reversed string, but there are garbage characters appended to it in my console print.</p>
  
  <p>Is this a "legal" operation in terms of returning to buffers? Can someone please critique my code and suggest a better alternative if it is not the right approach?</p>
  
  <p>Thanks.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  char *reverse_string(char *input_string);
  
  char *reverse_string(char *input_string)
  {
      int i=0;
      int j=0;
      char *return_string;
      char filled_buffer[16];
      while (input_string[i]!='\0')
          i++;
      while (i!=0)
      {
          filled_buffer[j]=input_string[i-1];
          i--;
          j++;
      }
      return_string=filled_buffer;
      printf("%s", return_string);
      return return_string;
  }
  
  int main (void) 
  {
      char *returned_string;
      returned_string=reverse_string("tasdflkj");
      printf("%s", returned_string);
      return  1;
  }
  </code></pre>
  
  <p>This is my output from Xcode - jklfdsat\347\322̲\227\377\231\235</p>