try thisCode:void makeitwork ( unsigned char* input, unsigned char* output, unsigned inputlength ) { // index of the new array unsigned int tempindex = 0; // alloc new array with the new bytes unsigned char* temp = new unsigned char[inputlength + (inputlength / 4) + 1]; ZeroMemory(temp, inputlength + (inputlength / 4)+1); for(unsigned int i = 0; i < inputlength; ++i) { temp[tempindex++] = input[i]; // keep copying the input data to the temp buffer if((i+1) % 4 == 0) // insert here? { temp[tempindex++] = '-'; // = 0; } } // copy to the output memcpy(output, temp, inputlength + (inputlength / 4) + 1); delete[] temp; } int _tmain(int argc, _TCHAR* argv[]) { char* teste = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; char* teste2 = new char[strlen(teste) + (strlen(teste) / 4) + 1]; makeitwork((unsigned char*)teste, (unsigned char*)teste2, strlen(teste)); cout << teste2 << endl; system("PAUSE"); }




Reply With Quote