title: Understanding the strdup function
body: <p>I tried to build my own strdup function, as I understand the  function is supposed to work as strcpy but with a string that can be used in another function, but in my prototype I dont understand why my chars are not copied.</p>
  
  <p>I have made this prototype, but I dont understand why the pointer that my function return doesn't display my string</p>
  
  <pre><code>char            *my_strdup(char *str)
  {
    char          *new_str;
    char          *to_copy;
    int           i;
  
    to_copy = str;
    i = strlen(str + 1);
    new_str = malloc(sizeof(*new_str) * i + 1);
    while(i - 1 &gt; 0)
      {
        *new_str = *to_copy;
        new_str++;
        to_copy++;
        i--;
      }
    return(new_str);
  }
  </code></pre>
  
  <p>and here is my test function:</p>
  
  <pre><code>int             main()
  {
    char          *str;
  
    str = my_strdup("helloo");
    printf("%s\n", str);
  }
  </code></pre>