title: Implementation of strdup() in C programming
body: <p>I'm working on the implementation of <code>strdup()</code> in C, I'm new to C and I'm trying to build my own library. I'm using the actual <code>strdup()</code> from <code>string.h</code> to test mine and I run into a bus error when I test my source against a main program but none when I use the actual <code>strdup()</code>. Also I can't use any existing functions excluding <code>malloc()</code>.</p>
  
  <p>Source code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  char *ft_strdup(char *src)
  {
  
      char *str;
      int len;
  
      while (src[len])
          len++;
      str = (char*)malloc(sizeof(*str) * (len+1));
      while (*src)
          *str++ = *src++;
      *str = '\0';
      return (str);
  }
  </code></pre>
  
  <p>Why do I keep getting a bus error?</p>