Hey, guys. I'm having trouble with creating a code for a recursive binary search. Whenever I run the code, it says "Segmentation fault (core dumped)". What should I change in my code? Here it is:
Code:
while(lower<=upper){
input2(&search);
if(search==-1)
printf("break;");
printf("Found %d at index %d", search, binary(array, n, search, lower, upper));
}
int binary(int array, int n, int search, int lower, int upper){
int middle;
lower=0;
upper=n-1;
middle=(lower+upper)/2;
if (array[middle] > search) // key is in lower subset
return binary(array, n, search, lower, middle-1);
else if (array[middle] < search) // key is in upper subset
return binary(array, n, search, middle+1, upper);
else // key has been found
return middle;
}