Lets say I have a prepend function:
//for example xMessage = "apple";
//for example yMessage = "juice";
//answer should be newMessage = "applejuice"
char* concat(char *xMessage, int xSize, char* yMessage, int ySize){
char newMessage[xSize+ySize];
for(....){
//copyxMessage
}
for(....){
//copyYMessage
}
return (char *) newMessage;
}
I know I can use strings, but would preferably keep them as an array of bytes. What could be the best solution for this to avoid the error of returning a local pointer.
SOLUTION: Create a vector or deque of uint8_t depending on the needs of the type of manipulation/algorithms of RAW data. I ended up using a std::vector<uint8_t>. Ex.
std::vector<uint8_t> data(buffer + bytesIn);
Due to in my case receiving data from a socket.
Edit: After reading the replies, the most convenient solution was to create a vector of chars or a string. Since I had a bunch of bytes being sent I decided to go with a std::vector<uint8_t>
due to more manipulation I had to do later in the program. Thank you everyone for making me realize that and helping me with this. The reason I was messing with raw char pointers is because the data I was dealing with was RAW data, but converting it into a vector it was easier to manipulate the data, than dealing with char pointers.