this is my code (find.c) :
#include "helpers.h"
const int HAY_MAX = 65536;
int main(int argc, char * argv[ ])
{
if (argc != 2)
{
printf("Usage: %s need\n", argv[0]);
return 1;
}
int needle = atoi(argv[1]);
int size;
int haystack[HAY_MAX];
for (size = 0; size < HAY_MAX; size++)
{
printf("\nhaystack[ % d] = ", size);
int straw = get_int( );
if (straw == INT_MAX)
break;
haystack[size] = straw;
}
printf("\n");
sort(haystack, size));
if (search(needle, haystack, size))
{
printf("\nFound needle in haystack!\n\n");
return 0;
}
else
{
printf("\nDidn't find needle in haystack.\n\n");
return 1;
}
}
code (helpers.c):
bool search(int value, int array[ ], int n)
{
int max = n - 1;
int min = 0;
while (max >= min)
{
int mid = (min + max)/2;
if(array[mid] < value)
min = mid + 1;
else if (array[mid] > value)
max = mid - 1;
else
return true;
}
return false;
}
void sort(int values[ ], int n)
{
int count[65536] = {0};
int current = 0;
for(int i = 0; i < n; i++)
{
count[values[i]]++;
}
for(int i = 0; i < 65536; i++)
{
while(count[i] != 0)
{
values[current] = i;
count[i]--;
current++;
}
}
return;
}
i'm try alot, but when i'm check50 it's still error like this: https://cs50.me/checks/a17e931852e89daf3a9cdf408972c7b009dc3761
please help me to figure out my problems.