0

When checking my find program with check50 I get a :( frown at the second check, which is:

helpers.c compiles. expected exit code 0, not 1

The log file gives me additional info:

running clang -std=c11 -o find find.c helpers.c -lcs50 -lm... checking that program exited with status 0...

I don't know why I get that since my program compiles just fine with make all (as well as make find).

The program (including recursive binary search and counting sort) seems to work as expected. Following tests were successful:

./generate 1000 50 > numbers.txt // generate 1000 numbers including 127
./find 127 < numbers.txt // Found needle in haystack!
./find 128 < numbers.txt // Didn't find needle in haystack.

The following modifications were made to the source files:

/**find.c:*/

const int MAX = 65536; // this expression was removed

.

/**helpers.c:*/

bool search(int value, int values[], int n)
{
//...
return bisearch(value, values, left, right, n);
}

bool bisearch(int value, int values[], int left, int right, int n)
{
if (left > right)
    return false;
//...
if (values[middle] == value)
    return true;
//...
return bisearch(value, values, left, right, n);
}

void sort(int values[], int n)
{    
/...
return;
}

.

/**helpers.h:*/
#define MAX 65536 // this expression was added to replace const int MAX

bool search(int value, int values[], int n);
bool bisearch(int value, int values[], int left, int right, int n);
void sort(int values[], int n);
  • First time on the forums. I can edit my question if it is too long or not specific enough. – gunjx Sep 20 '17 at 19:46
  • check50 may be using its own copy of helpers.h and only looking at your helpers.c. Try moving your #define MAX to the top of helpers.c. It may be failing compilation when it runs into the symbol MAX. In most of these assignments, it is important to modify only the files they specifically ask you too. Anything else may cause issues with the autograder. – robert_x44 Sep 20 '17 at 20:26
  • Thanks for clarifying this. I removed the prototype of my self-created function "bisearch" from helpers.h and instead put it at the top of helpers.c. – gunjx Sep 23 '17 at 16:49
4

find.c and helpers.h cannot be altered. When check50 runs, it uses its own copies, so your alterations are lost. That will cause the compile to fail.

You need to make all of your changes in helpers.c

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Thank you robert. ;-) – Cliff B Sep 20 '17 at 21:06
  • Putting back the expression const int MAX = 65536; into find.c leads to me being unable to use MAX in my helpers.c file. I tried putting extern const int MAX; at the top of helpers.c but then I can't use expression int count[MAX] = {0}; Any help? – gunjx Sep 23 '17 at 16:55

You must log in to answer this question.

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