0
bool search(int value, int values[], int n)
{
// TODO: implement a searching algorithm       

    for (int i = 0; i < n; i++)
    {
        if(values[i] == value)
        {
            return i;
        }
        else
        {
            return -1;
        }

    } 
    return false;   
}

Why do I have the below error and program does not run?

jharvard@appliance (~/Dropbox/pset3/find): make helpers
clang -ggdb3 -O0 -std=c99 -Wall -Werror    helpers.c  -lcs50 -lm -o helpers
/usr/lib/gcc/i686-redhat-linux/4.8.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
jharvard@appliance (~/Dropbox/pset3/find): 

1 Answer 1

0

It doesn't work because you are returning an int value and your function returns a boolean:

bool search(int value, int values[], int n)

You see? remember that this function is conected with find.c soy you need to return "True" if value is in the array of "values[i]" if don't you return false.

1
  • ooo, i understand now, thank you very much German Rocha :)
    – Hang Man
    Dec 27, 2014 at 2:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .