Originally Posted by
tabstop
Something like this may be better:
Code:
void packetBuilder ( int count, string package ) {
short int *pack = new short int[count+4]; //don't know why you have count+5 there at all
stringstream dataStream( package );
// Save 0-3 for other purposes
for ( int i = 4; i < count+4; i++) {
dataStream >> hex >> pack[i];
}
sendData (static_cast<char *>(pack));
free(pack);
}
This is undefined behavior (new and free).
But what I don't understand is that since you have the data in a string, why not simply do
Code:
sendData(package.c_str());
?
Are you implying that your string consists of a number of shorts added together? That is, if we do
Code:
const short* p = reinterpret_cast<const short*>(package.c_str());
Then p[0] will be the first block of data and p[1] the next, etc?