Here are the errors:
test3.c: In function ‘main’:
test3.c:40: warning: passing argument 1 of ‘binary_srch’ from incompatible pointer type
test3.c:42: warning: suggest parentheses around assignment used as truth value
test3.c:29: warning: unused variable ‘top’
test3.c:28: warning: unused variable ‘bottom’
test3.c:27: warning: unused variable ‘middle’
test3.c: In function ‘binary_srch’:
test3.c:57: error: expected declaration specifiers before ‘top’
test3.c:58: error: expected declaration specifiers before ‘bottom’
test3.c:60: error: expected declaration specifiers before ‘while’
test3.c:72: error: expected ‘{’ at end of input
Here's the code.
Code:
//prototypes
int binary_srch ( char arr [], int length, int *found );
int main( void )
{
int arr[] = { 0, 2, 4, 5, 6, 7, 8, 9, 12, 14, 15};
int value;
int index;
int middle;
int bottom;
int top;
int found;
found = FALSE;
printf("Enter number to find..\n");
scanf("%d",&value);
index =binary_srch (arr,10,&found);
if(found = TRUE)
printf("%d found at position %d\n",value,index);
else
printf("NUMBER NOT FOUND!\n");
return 0;
}
int binary_srch ( char arr [], int length, int *found )
int top;
int bottom;
int middle;
top = 10;
bottom = 0;
while ( bottom <= top )
{ middle = (bottom + top) /2;
if( arr[middle] > value)
top = middle - 1;
else if (arr[middle] < value)
bottom = middle + 1;
else
*found = TRUE;
return middle;
}
Thanks a bunch!