The following will not compile, because a the value of 'n' must be know at compile time (not runtime).
scanf("%d",&n);
int a[n];
You must do a runtime memory allocation
scanf("%d",&n);
int *a = malloc(sizeof(int) * n);
...
free(a);
return 0;
Your compare function takes a pointer (
compare(void *p, int a[], int n)) as the first parameter and you are passing it the address of a pointer (
compare(&p, a, n)), which is a pointer to a pointer (**p). Therefore, I conclude that your compare function should be taking a pointer to a pointer (
compare(void **p, int a[], int n)).
This will change how you refer to the 'p' variable in the comparison function:
instead of
*(int*)p
you would use
*(int*)*p
Additionaly, Your compare function either returns an
undefined value if 'f' is not equal to '1' or whatever value is stored in a[0].
You need to go back to the drawing board and find out exactly what you are try to accomplish with this code. Because whatever it is, this is not it.
Write a detailed description of the compare function. What is the expected input and output? This is what you need to test at the function call level.
Take each line apart to see what it is doing. Write out a description of the line in English (or language of choice). If you can do that, then you understand it; otherwise you do not.