In my following code, I made buffer as a 2D array created using malloc(r * c * sizeof(double*));. I want to copy the first 12 elements of buffer (i.e. the first 4 rows) into the second one temp using memcpy.
double *buffer = malloc(10 * 3 * sizeof(double*));
double *temp = malloc(4 * 3 * sizeof(double*));
for (int i = 0; i < 4; ++i) {
memcpy(*(temp+ i*3), *(buffer + i*3), 3 * sizeof(double));
}
I get this error:
memcpy(*(temp+ i*3), *(buffer + i*3), 3 * sizeof(double));
^~~~~~~~~~~~~~~~~~~~~~~~~~
Can someone tell me why?
Thank you in advance.