title: During string reversal extra character is added for array size less than 5 in c using jni
body: <p>I'm writing a basic string reversal program in c by getting the input from java through jni. I'm initialising the output array dynamically by getting the output of the input string. But the output always has an extra letter if the length of the string is less than 5. For example the output for "hello" is "ollehp". So how can I fix this?</p>
  
  <p>This is my code.</p>
  
  <pre><code>JNIEXPORT jstring JNICALL Java_JavaTest_reversal(JNIEnv * env, jobject obj, jstring input)
  {
          const char *str = (*env)-&gt;GetStringUTFChars(env, input, 0);
          const int length = (int)strlen(str);
          int l = length;
          char output[l];
          int j = length-1;
          for(int i = 0 ; i &lt; length ; i++)
          {
                  output[j] = str[i];
                  j--;
          }
          (*env)-&gt;ReleaseStringUTFChars(env, input, str);
          printf("output %s \n",output);
          return (*env)-&gt;NewStringUTF(env, output);
  }
  </code></pre>