   Char array help?
typedef char charbuf [256];void CNetMessageApp::LoadByte(char ID) {charbuf c;c[0] = ID;LoadBytes(c, 1);finish();}char CNetMessageApp::UnLoadByte() {charbuf c;UnLoadBytes (c);return c[0];}void LoadBytes(charbuf& inputbuffer, int n); //Load a char set into the message buffervoid UnLoadBytes(charbuf& destbuffer); //Unload a char set from the buffervoid finish(); //set the state object to full. No more data to be loadedvoid CNetMessage::LoadBytes(charbuf& inputbuffer, int n) {for (int i = 0; i < n; i++)buffer = inputbuffer;state = READING;}void CNetMessage::UnLoadBytes(charbuf& destbuffer) {for (int i=0; i < this->NumToUnLoad(); i++)destbuffer = buffer;reset();}I am using a network class made by someone online, but I have no idea how i should go about making LoadByte(char ID) and UnLoadByte(char ID) functions use a char array argument properly.I get user input as a string and then I convert it to char* with its own allocation, but the class member functions as you can see only accepts a single char, i want it to accept an array of chars instead of one.I tried making it work but when my program runs it crashes, I think its because its Load_Bytes(char *text) fail to do what it should.//should load a byte arrayvoid CNetMessageApp::Load_Bytes(char *text) {    charbuf *c;c = new charbuf[strlen(text)+1];strcpy(c,text);LoadBytes(*c, strlen(text)+1);finish();delete[] c;}   //temp string std::string temp_str; //gets keypresseskeypress.handle_input(); return the string of chars to temp stringtemp_str = keypress.Return_String();//allocates memory for char* wordswords = new char[temp_str.length()+1]; //copy string to char*strcpy(words,temp_str.c_str()); //loads char* in mesg to be sentmsg.Load_Bytes(words); // sends the mesg over the socket, program seems to crash heretcpclient->Send(msg);
  That buffer class looks terrible. I don't understand how it's even supposed to work.You can easily use either a stringstream, or a std::vector, as a buffer for networking. The benefit is that those classes are easy to understand, too.Using a vector:// string encoding: length + datainline operator<<(std::vector<char> &target, std::string const &src){  size_T l = src.length();  target << l;  target.insert(target.end(), src.begin(), src.end());}// little-endian, variable-length int encoding (a la Google Protocol Buffers)inline operator<<(std::vector<char> &target, size_t const &i){  do {    char ch = i & 0x7f;    i >>= 7;    if (i != 0) { ch |= 0x80;    }    target.insert(target.end(), ch);  }  while (i != 0);}  std::vector<char> myPacket;  myPacket << "some string here";  int r = ::send(socket, &myPacket[0], myPacket.size(), 0);Unpacking after receipt is just the reverse.