I want to do a function that is able of shift array elements but the arrays can be of ints or of a struct defined by me. How do I iterate on pointers to void arrays?
This is my code so far for this example I'm using Ints but I plan to use the same function with other data types:
void shift(const void *source, int pos, int lenght){
memmove(&source[pos], &source[pos+1], sizeof(int)*(lenght-pos-1) );
}
int main(int argc, char *argv[]) {
int a[10] = {1,2,3,4,5,6};
shift(a, 3, 10);
}
[..]operator acts as a dereference. You cannot dereference avoidtype. Your only real option is to cast everything tochar*along with thesizeof (your_type)and adjust the indexing as required.void *you would have a variable of typevoid **, but that's not what you have. You need to show exactly how this function is called. Please update your question with a minimal reproducible example.