I need to copy modified data that is stored in an char* to another char* but I get an access violation error.
Here is the code
int EncryptData(char *data_source, char *data_cipher, size_t sizeofdata)
{
char *tmp_data;
long long int digit;
tmp_data = new char[sizeofdata];
/*
Do some calculations here with some data and then store it in tmp_data.
*/
memcpy(data_cipher, tmp_data, sizeof(data_cipher));
delete[] tmp_data;
}
// char* dest
int main()
{
char *dest = "";
encryption.EncryptData("Hello world", dest, strlen("Hello world"));
for(int i = 0; i < strlen(dest); i++)
std::cout << dest[i];
}
When I copy tmp_data
to data_cipher
, dest
should then hold the modiefied values. But I get an acces violation when I try to copy the data.
How do I fix it?