I allocated a space of memory with malloc (to have a matrix) and I have to move the "row" at the end, I tried this:
double **dataset = fill_dataset(....);
double* temp = malloc((d + 1) * sizeof(double ));
for (int i = 0; i < d + 1; i++) {
temp[i] = dataset[0][i];
}
memmove(&dataset[0], &dataset[1], (p_in_retained - 1) * sizeof(double *));
for (int i = 0; i < d + 1; i++) {
dataset[p_in_retained - 1][i] = temp[i];
}
p_in_retained is the number of rows, the problem is that when the second loop ends I have the same element in the last and the second to last element, for example, suppose that this is the initial matrix:
id col1 col2
1 1 1
2 6 3
3 8 2
4 9 1
what I expect to have is the following:
id col1 col2
2 6 3
3 8 2
4 9 1
1 1 1
what I get is:
id col1 col2
2 6 3
3 8 2
1 1 1
1 1 1
Array od pointers (ie double pointer).
Real 2D array Use pointers to arrays. It makes it much easier
malloc version:
https://godbolt.org/z/dWMWr5qr3