0

im not sure if my binary search code is correct, when I try to compile it I get the following message:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2 /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain' clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [helpers] Error 1

my code is below:

#include <cs50.h>
#include <stdio.h>
#include <string.h>

#include "helpers.h"


/**
* Returns true if value is in array of n values, else false.
*/



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

if (n < 0)
    {
        printf("n must be a non-negative integer\n");
        return false;
    }

else
    {
            for (int i = 0; i < n; i++)

            {
                int middlevalue = values[n/2];
                printf("Middle value is %d\n", middlevalue);
             if (middlevalue == value)
                {
                     printf("Number is found!\n");
                     return true;
                }

            }
    }


            int middlevalue = values[n/2];
            if (value > middlevalue)
                        {

                         for (int i = 0; (values[n/2] < i < n) ; i++)
                            {
                            if (i == value)

                                {
                                printf("Number is found!\n");
                                return true;
                                }
                            }
                        }

                    else if (value < middlevalue)
                        {
                            for (int i = 0; (0 < i < values[n/2]) ; i++)
                            {
                            if (i == value)

                                {
                                printf("Number is found!\n");
                                return true;
                                }
                            }

                        }

                else 
                {
                    printf("Number cannot be found!\n");
                }

return false;
}

if you could look it over that would be great, thank you!

0
1

You are getting this error message because, apparently the compiler couldn't find the main function in your program. Most probably you are compiling your code like this:

make helpers

the compiler does not find any main function in you program as a result it yells at you with this extremely long error message. Instead you should compile your code with:

make find

this will compile the program which looks for a specific number in the list

make generate 

this will compile the program that will generate random numbers

You must log in to answer this question.

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