if anybody can help me with this code...plz
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void * scrambleArr(void * arr, int numElem, int elemSize,int (*func)(void*));
int func(void *x);
void main( )
{
int a[7]={1,2,3,4,5,6,7};
int i;
int *p = NULL;
p = scrambleArr(a, 7, sizeof(int),func);
for (i = 0; i < 7; i++)
printf("%d", *p);
printf("\n");
}
int func(void *x) //i want to return the new place of the char in new array...!?
{
int index[7]={4,2,0,5,1,6,3};
int *p=index[0];
return p;
}
void *scrambleArr(void *arr, int numElem, int elemSize,int (*func)(void*))
{
void* newArr = (void*) malloc(elemSize * numElem);
unsigned char* new_ptr = newArr;
unsigned char* orig_ptr =arr;
char* orig_idx_ptr;
int* idx_ptr;
int i;
for ( i=0 ; i < numElem ; i++ )
{
idx_ptr = func(orig_ptr) + i; // Get next entry from indArr
orig_idx_ptr = orig_ptr +(*idx_ptr * elemSize); // find element in arr to copy
memcpy(new_ptr, orig_idx_ptr, elemSize); // copy it to the new array
new_ptr += elemSize; // move newArr to next element ready for next copy
}
return newArr;
}