title: Understanding BufferStruct + WriteMemoryCallback
body: <pre><code>struct BufferStruct
  {
  char * buffer;
  size_t size;
  };
  
  // This is the function we pass to LC, which writes the output to a BufferStruct
  static size_t WriteMemoryCallback
  (void *ptr, size_t size, size_t nmemb, void *data)
  {
  size_t realsize = size * nmemb;
  
  struct BufferStruct * mem = (struct BufferStruct *) data;
  
  mem-&gt;buffer = realloc(mem-&gt;buffer, mem-&gt;size + realsize + 1);
  
  if ( mem-&gt;buffer )
  {
  memcpy( &amp;( mem-&gt;buffer[ mem-&gt;size ] ), ptr, realsize );
  mem-&gt;size += realsize;
  mem-&gt;buffer[ mem-&gt;size ] = 0;
  }
  return realsize;
  }
  </code></pre>
  
  <p>I found this <a href="http://www.hackthissite.org/articles/read/1078" rel="nofollow">here</a></p>
  
  <p>What is he trying to do here? Espacially by multiplying those size_t's?
  He is trying to show how to export the html code you get to a file.
  Why is it necesarry to write a complex (for me) function like that?
  Thanks if someone can explain or post some source that can help me understand this :)</p>