title: char array to uint8_t array
body: <p>this is one area of C/C++ that i have never been good at.</p>
  
  <p>my problem is that i have a string that will need to eventually contain some null characters.  treating everything as a char array (or string) won't work, as things tend to crap out when they find the first null.  so i thought, ok, i'll switch over to uint8_t, so everything is just a number.  i can move things around as needed, and cast it back to a char when i'm ready.</p>
  
  <p>my main question right now is: how can i copy a portion of a string to an uint8_t buffer?  </p>
  
  <p>effectively, i'd like to do something like:</p>
  
  <pre><code>std::string s = "abcdefghi";
  uint8_t *val = (uint8_t*)malloc(s.length() + 1);
  memset(val, 0, s.length() + 1);
  
  // Assume offset is just some number
  memcpy(val + offset, s.substr(1, 5).c_str(), 5);
  </code></pre>
  
  <p>obviously, i get an error when i try this.  there is probably some sort of trickery that can be done in the first argument of the memcpy (i see stuff like (*(uint8_t*)) online, and have no clue what that means). </p>
  
  <p>any help on what to do?</p>
  
  <p>and while i am here, how can i easily cast this back to a char array?  just static_cast the uint8_t pointer to a char pointer?</p>
  
  <p>thanks a lot.  </p>