I'm stuck with my pset3 helpers.c
function, I'm getting the following error when I compile without the last return
statement
error: control may reach end of non-void function [-Werror,-Wreturn-type]
}
^
1 error generated.
make: *** [find] Error 1
But if I use the last return statement, program is not printing any output in the terminal. I'm really confused about the use of return
statement. Is it necessary to have a return call at the end of this do-while loop, because I have a return call inside the loop for all possible outputs ? Where am I going wrong?, any help is appreciated.
bool search(int value, int values[], int n)
{
int start = 0; int end = n-1; bool check = false; int k = 0;
do
{
k = (int) (start + end)/2;
if (values[k] == value)
{
check = true;
return true;
}
else if (values[k] > value)
{
end = k - 1;
}
else if (values[k] < value)
{
start = k + 1;
}
else if (start >= end)
{
check = true;
return false;
}
else
{
check = true;
return false;
}
}
while(check == false);
return true;
}