I am getting the following error when I compile my helpers file
jharvard@appliance (~/Dropbox/pset3/find): make helpers
clang -ggdb3 -O0 -std=c99 -Wall -Werror helpers.c -lcs50 -lm -o helpers
helpers.c:33:13: error: expected expression
else
^
1 error generated.
make: *** [helpers] Error 1
jharvard@appliance (~/Dropbox/pset3/find):
My helpers file is reproduced below.
/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{ int i=0;
while (i<n )
{
if (values[i] == value)
{
return true;
}
else
{
return false;
}
i++;
else
return value[i];
}
// TODO: implement a searching algorithm
/**
* Sorts array of n values.
*/
void sort(int values[], int n);
// TODO: implement an O(n^2) sorting algorithm
for (int i = 1; i < n-1; i++)
{
int min = i;
for (int j = i+1; j < n; j++)
{
if (values[j]<values[min])
{
min = j;
}
values [min] = values [i];
};
}
return 0;
}
I can get rid off this expected expression error if I remove the code else return value[i]; Then I get another errorundefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [helpers] Error 1.
There are several other lines associated with this error. But I am unable to keep their format. Hence I have deleted them
While I could understand the foo() example provided by Kareem in connection with may reach end of non-void function” error, I am not having any clue how to get rid off that error. It appears to persist with for or while loops. Any guidance to get rid of this error will be appreciated. It appears a few others had similar errors while reviewing Stack Exchange. uma1966