title: how to use memcpy to initialize a char pointer in struct
body: <p>this is how I define struct.</p>
  
  <pre><code>struct urlFormat
  {
        int port;
        char *host;
        char *path;
        int cat;
        char *status;
  };
  </code></pre>
  
  <p>this is how I initialize strcut and allocate the space for the pointer.</p>
  
  <pre><code>struct urlFormat *res;
  res = malloc(sizeof(struct urlFormat));
  </code></pre>
  
  <p>when I used memcpy() function, it reported segmentation fault.</p>
  
  <pre><code>char *ptr1 = (char *)url;
    int len = strlen(ptr1);
    memcpy(res-&gt;host, ptr1, len);
  </code></pre>
  
  <p>I don't know how to solve it.</p>