title: C++ copy content of structure
body: <p>I have a problem with copying the content of a structure..
  following situation...I have a struct arg_struct in my class Session:</p>
  
  <pre><code>struct Session::arg_struct
  {
      const char* targetFilePath;
      const char* url;
      unsigned int thread_id;
      Session::ThreadFinishedCallbackFunction callback;
  };
  </code></pre>
  
  <p>and in one of my method I start a thread and give the struct to the function that will be executed:</p>
  
  <pre><code>{
  ...
  arg_struct args;
  args.targetFilePath = targetFilePath;
  args.url = req_url;
  args.thread_id = ++mThread_id;
  args.callback = callback;
  
  curl_global_init(CURL_GLOBAL_ALL);
  
  error = pthread_create(&amp;thread,NULL,download,&amp;args);
  
  }
  </code></pre>
  
  <p>Now the download function will be executed:</p>
  
  <pre><code>void* download(void* arguments)
  {
  
  Session::arg_struct ar = *(Session::arg_struct*) arguments;
  Session::arg_struct args;
  args.targetFilePath = new char[strlen(ar.targetFilePath)];
  args.url = new char[strlen(ar.url)];
  strcpy(const_cast&lt;char*&gt;(args.targetFilePath),ar.targetFilePath);
  strcpy(const_cast&lt;char*&gt;(args.url),ar.url);
  args.callback = ar.callback;
  args.thread_id = ar.thread_id;
  cout &lt;&lt; "copied" &lt;&lt; endl;
  CURL *curl;
  FILE* datafile;
  
  datafile = fopen(args.targetFilePath, "w");
  
  if(datafile != NULL)
  {
  
      curl = curl_easy_init();
      curl_easy_setopt(curl,CURLOPT_URL,args.url);
      curl_easy_setopt(curl,CURLOPT_WRITEDATA,datafile);
      curl_easy_perform(curl);
      curl_easy_cleanup(curl);
      fclose(datafile);
  
  } else {
      cout &lt;&lt; "error: failed to open file!" &lt;&lt; endl;
      return NULL;
  }
  </code></pre>
  
  <p>At the beginning of the download function I copy the struct (I quess ;) ) but I got the error that the file can not be opened. The problem is that when I try to open the file with fopen() the struct is empty. It seems that I havent copied the struct correctly or the pointer to the struct (void* arguments) is allready not useable. Have you got any suggestions?</p>