0

When I run check50 it states that helpers.c doesn't compile, but it finds the numbers correctly in the arrays. I'm lost. Any help is appreciated.

~/workspace/pset3/find/ $ check50 2015.fall.pset3.find helpers.c
:) helpers.c exists
:( helpers.c compiles
    \ expected an exit code of 0, not standard error of "/tmp/find-9VOFcu.o: In function `main':..."
:| finds 42 in {42,43,44}
    \ can't check until a frown turns upside down
:| finds 42 in {41,42,43}
    \ can't check until a frown turns upside down
:| finds 42 in {40,41,42}
   \ can't check until a frown turns upside down
:| finds 42 in {41,42,43,44}
   \ can't check until a frown turns upside down
:| finds 42 in {40,41,42,43}
   \ can't check until a frown turns upside down
:| finds 42 in {39,40,41,42}
   \ can't check until a frown turns upside down
:| doesn't find 42 in {39,40,41}
   \ can't check until a frown turns upside down
:| doesn't find 42 in {39,40,41,43}
   \ can't check until a frown turns upside down

Here is my helper.c file.

bool BinarySearch(int value, int values[], int n)
{
int min = 0;
int max = n - 1;
while (max >= min)
{
    int mid = (max + min)/2;

    if (values[mid] == value)
    {
        return true;
    }
    if (values[mid] > value)
    {
        max = mid - 1;
    }
    else if (values[mid] < value)
    {
        min = mid + 1;
    }
}
return false;
}


void sort(int values[], int n)
{
    int i, j, h, min;

for (i = 0; i < n - 1; i++)
{
    min = i;

    for (j = i + 1; j < n; j++)
    {
        if (values[j] < values[min])
        {
            min = j;
        }
    }
    if (min != 1)
    {
        h = values[i];
        values[i] = values[min];
        values[min] = h;
    }
}
return;
}
1
  • The content above is not a complete .c file. Where are the #includes? – Cliff B Oct 12 '16 at 19:42
0

The instructions I'm looking at say that you may not change the declaration of the search function (http://cdn.cs50.net/2016/x/psets/3/pset3/pset3.html#search_2). You've renamed the function BinarySearch(). If that doesn't match with the name used to call it in main(), and its prototype in helpers.h, find will not build.

But as the instructions indicate not to change the declaration, I'd recommend renaming BinarySearch() back to search() in helpers.c, and keeping it as search() in the other 2 locations.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .