I am stuck with the implementation of the sort function. I have written a code, but I can't check if the code is correct. This is what I have done thus far:
void sort(int values[], int n)
{
for (int i = 1; i < n; i++)
{
int element = (int) values[i];
int j = i;
while (j > 0 && (int) values[j-1] > element)
{
values[j] = values[j-1];
j = j - 1;
}
values[j] = element;
printf("%i\n", values[j]);
}
return values[];
}
Here things become strange. When I run find.c the output is correct. However when I use gdb to check the program and I go to the appropriate line and type 'step' I go to the sort function in helpers.c. When I go to the next line however gdb returns to find.c. It seems that find.c doesn't use any of the lines in my sort function. Moreover I put a print command after each iteration to check if the sort function truly sorts the input, but when I run the program these values aren't printed.
I don't understand why my sort function doesn't seem to work. The linear search function does work, so it appears that there is nothing wrong with the link between find.c and helpers.c. Any help with how I can overcome this problem is therefore much appreciated.
Max
return values[]
doesn't make sense. values is name of array, why are you using values[] ? Also as @Andrew G pointed out, make sure to re-compile every time, you make changes to your C-program