title: Ways to interpret groups of bytes in a curl result as other data types
body: <p>I'm trying to write a program which will query a URL using curl and retrieve a string of bytes. The returned data than needs to be interpreted as various data types; an int followed by a sequence structures.</p>
  
  <p>The curl write back function must have a prototype of:</p>
  
  <pre><code>size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
  </code></pre>
  
  <p>I've seen various examples where the returned data is stored in a buffer either as characters directly in memory or as a string object.</p>
  
  <p>If I have a character array, then I know that I can interpret a portion of it as a structure with code like this:</p>
  
  <pre><code>struct mystruct {
      //define struct
  };
  
  char *buffer;
  //push some data into the buffer
  char *read_position;
  read_position = buffer + 5;
  test = (mystruct *)buffer;
  </code></pre>
  
  <p>I have two related questions. Firstly, is there a better way of using curl to retrieve binary data and pushing it into structures, rather than reading it directly into memory as characters. Secondly if reading into memory as a character buffer is the way to go, is my code above a sensible way to interpret the chunks of memory as different data types?</p>