I have to create a binary search using pointer for a school assignment. I haven't had much luck getting it to work (please keeping mocking and laughter to a minimum)
It gives me the standard "Why the F are you screwing around with Memory that ain't yours" error.
int Search(int num[], int n, int target)
{
int pos = 0, *first=num, *mid, *last;
last=(num+n);
SortData(num, n);
printf("%d", num[1]);
while (first <=last)
{
mid=(first+last)/2;
if (target >mid)
first=mid+1;
else if (target <mid)
last=mid-1;
else
{ first = last+1;
return (*mid-2);
}}
return -1;
}
It gives me the standard "Why the F are you screwing around with Memory that ain't yours" error.