I have an array of pointer to a struct.
I tried to use the first answer of this question to try to solve this problem, but I got a seg fault:
After try this code, I tryed to use this function to do the shuffling:
static void shuffle(void *array, size_t n, size_t size) {
void * aux;
aux = malloc (size);
if (n > 1) {
size_t i;
for (i = 0; i < n - 1; ++i) {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
memcpy(aux, array[j], size);
memcpy(array[j], array[i], size);
memcpy(array[i], aux, size);
}
}
}
But i got the following error:
warning: dereferencing 'void *' pointer [enable by default]
error: invalid use of void expression
I got this warning and error 3 times: one for each memcpy().
EDIT
I changed the code because I was trying to use this new one instead the old one.