title: Why does a string returned from my function print as garbage?
body: <p>I am trying to convert the string to upper case, e.g. convert <code>test.pdf</code> to <code>TEST.PDF</code>. However, when I try to print returned value using <code>printf</code>, it prints some junk value. What am I doing wrong? </p>
  
  <pre><code>char *covertToUpper(char *str)
  {
      int i = 0;
      int len = 0;
  
      len = strlen(str);
      char newstr[len+1];
  
      for(i = 0; str[i]; i++)
      {
         newstr[i] = toupper(str[i]);
      }
      //terminate string
      newstr[i]= '\0';
      return  newstr;
  }
  </code></pre>