How does one copy the data that is pointed to by another pointer?
I have the following
void *startgpswatchdog(void *ptr)
{
GPSLocation *destination;
*destination = (GPSLocation *) ptr;
Will this do this correctly?
I free the data that is passed into thread after passing it, so I need to copy the data.
If you want to copy data you should allocate new memory via malloc
, then copy your memory via memcpy
.
void *startgpswatchdog(void *ptr)
{
GPSLocation *destination = malloc(sizeof(GPSLocation));
memcpy(destination, ptr, sizeof(GPSLocation));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With