title: How do I transfer certain characters from one string to another?
body: <p>I want to save some characters from one string to another.</p>
  
  <p>I tried going from character to character from one string and saving them to the other string.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  int main()
  {
      char *sent, *rec;
      int i, a;
      sent = malloc(100);
      rec = malloc(100);
      gets(sent);
      a = strlen(sent);
      for (i = 0; i &lt; 3; i++)
          *(rec + i) = *(sent + i);
      a = strlen(rec);
      rec = realloc(rec, 4);
      puts(rec);
  }
  </code></pre>
  
  <p>If I input "Hello world" the expected output should be"Hel", but it is "Hel" and some random characters.And also I dont understand why is the lenght of rec equal to 14.</p>