title: Strings with Realloc in C
body: <p>I am trying to use realloc function as making the array bigger  as the user entered names. It gives me an error when I add 5. element, the error like : 
  <strong>* glibc detected <em></strong> ./a.out: realloc(): invalid next size: 0x00000000017d2010 *</em>*
  And the code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(void){
    char **mtn = NULL;
    char x[30];
    int i = 0;
  
    while ( strcmp(gets(x), "finish") ){
      mtn = realloc( mtn, i*sizeof(char) );
     // mtn[i] = realloc( mtn[i], sizeof(x) ); // tried but didnt work
      mtn[i] = x;
      i++;
    }
    puts(mtn[1]);
  
    return 0;
  }
  </code></pre>