title: how to duplicate a string with malloc
body: <p>I have this exercise where I need to duplicate a string using a malloc, I'm not sure where my error is (I have a segmentation fault). </p>
  
  <pre><code>/* Like the strdup() function. It creates a copy of the string on the heap.
  * @note The copy is allocated using malloc().
  * @to of warning the user is responsible for freeing the memory allocated for the new string
  * @param str the string to duplicate
  */    
  char * IMPLEMENT(duplicateString)(const char * str) {
      if(str==NULL){
          return NULL;
      }
  
      char *str2;
      str2=malloc(sizeof(*str));
  
      while(str!='\0'){
          *str2=*str;
          str=str+1;
          str2=str2+1;
      }
  
      *str2='\0';
  
      return str2;
  }
  </code></pre>