Where is the segmentation fault occurring in this program?
Thanks!
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <math.h>
#include <stdio.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
//Recursive Search
bool binsearch(int key, int array[], int min, int max, int end)
{
int mid1 = 0;
int mid = 0;
if(max < min)
{
end = 0;
return false;
}
else
{
mid1 = max / 2;
mid = round(mid1);
if(array[mid] < key)
{
return binsearch(key, array, mid + 1, max, end);
}
else if(array[mid] < key)
{
return binsearch(key, array, min, mid - 1, end);
}
else
{
end = end + 1;
return true;
}
}
}
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{
int j = 0;
int end = 0;
binsearch(value, values, j, n, end);
return end;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
int j = 0;
for(int i = 0;i < n;i++)
{
for(int k = 0;k < n;k++)
{
if(values[k] < values[k + 1])
{
values[k + 1] = j;
values[k + 1] = values[k];
values[k] = j;
}
}
}
return ;
}