title: How to read x characters from position y in a char * buffer?
body: <p>I am reading through a buffer (char *) and i have a cursor, where i am tracking my starting position of the buffer, is there a way to copy characters 7-64 out of the buffer, or is my best bet to just loop the buffer from poistion x to position y?</p>
  
  <p>The size of the destination buffer is the result of another function dynamically computed</p>
  
  <p>Initializing this returns</p>
  
  <p><code>variable-sized object 'version' may not be initialized</code></p>
  
  <p>Relevant code parts:</p>
  
  <pre><code>int32_t size = this-&gt;getObjectSizeForMarker(cursor, length, buffer);
  cursor = cursor + 8; //advance cursor past marker and size
  char version[size] = this-&gt;getObjectForSizeAndCursor(size, cursor, buffer);
  </code></pre>
  
  <p>-</p>
  
  <pre><code>char* FileReader::getObjectForSizeAndCursor(int32_t size, int cursor, char *buffer) {
    char destination[size];
    memcpy(destination, buffer + cursor, size);
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>int32_t FileReader::getObjectSizeForMarker(int cursor, int eof, char * buffer) {
    //skip the marker and read next 4 byes
    cursor = cursor + 4; //skip marker and read 4
    unsigned char *ptr = (unsigned char *)buffer + cursor;
    int32_t objSize = (ptr[0] &lt;&lt; 24) | (ptr[1] &lt;&lt; 16) | (ptr[2] &lt;&lt; 8) | ptr[3];
    return objSize;
  
  }
  </code></pre>