I'm trying to make helpers work and for the life of me can't seem to convince it to do so.
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include "helpers.h"
int i;
/**
* Returns true if value is in array of n values, else false.
*/
//Binary Search
bool search(int value, int values[], int n)
{
// TODO: implement a searching algorithm
int MAX = n - 1;
int MIN = 0;
while (MIN <= MAX)
{
int MIDDLE = (MIN + MAX)/2;
if (value == array[MIDDLE])
return true;
else if (value > array[MIDDLE])
{
MIN = MIDDLE + 1;
}
else if (value < array[MIDDLE])
{
MAX = MIDDLE - 1;
}
}
return false;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
// TODO: implement an O(n^2) sorting algorithm - linear sort
for (int i = 0; i < n, i++);
{
int index = values[i];
int j = i;
while (j > 0 && n[i-1] > index)
{
values[j] = values[j-1];
j = j - 1;
values[j] = index;
}
}
return;
}
The error code when I run it is as follows:
helpers.c:30:22: error: use of undeclared identifier 'array'
if (value == array[MIDDLE])
^
helpers.c:32:26: error: use of undeclared identifier 'array'
else if (value > array[MIDDLE])
^
helpers.c:36:26: error: use of undeclared identifier 'array'
else if (value < array[MIDDLE])
^
helpers.c:50:23: error: expression result unused [-Werror,-Wunused-value]
for (int i = 0; i < n, i++);
~ ^ ~
helpers.c:50:31: error: expected ';' in 'for' statement specifier
for (int i = 0; i < n, i++);
^
helpers.c:54:26: error: subscripted value is not an array, pointer, or vector
while (j > 0 && n[i-1] > index)
~^~~~
helpers.c:50:32: error: for loop has empty body [-Werror,-Wempty-body]
for (int i = 0; i < n, i++);
^
helpers.c:50:32: note: put the semicolon on a separate line to silence this warning
7 errors generated.
I've been scratching my head about this for a while and think I just need to be pointed in the right direction.
Thanks!