2

Here is the error code. Tried Make All. Tried several different sort & search algorithms and coding.

clang -ggdb3 -O0 -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
/tmp/find-3c23ac.o: In function `main':
/home/jharvard/Dropbox/pset3/find/find.c:55: undefined reference to `sort'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [find] Error 1

Here is the code that generates the error:

/**
* 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)
{
   // Implements a searching algorithm

   if (n < 1)
   {
   return false;
   }

   for (int i = 0; i < n; i++)
       {
       if (values[i] == value)
           return true;
       }
       return false;

/**
* Sorts array of n values.
*/
void sort(int values[], int n);

   // Implements an O(n^2) sorting algorithm

   void sort(int values[], int n);

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

       for (int j = i + 1; j < n; j++)
       {
           if(values[j] < values[min])
           {
               min = j;
           }
       values[min] = values[i];
   }
   return false;
   }
}

1 Answer 1

3

The error is basically saying that the function sort() doesn't exist. I can hear you already yelling that it does, but at the moment, it really doesn't. The real problem is that you have a simple structural problem. You didn't pair up the opening curly brace { in the function search(), so sort() is being treated as part of search() instead of a separate function.

Once you fix that, you're going to discover that you are also missing an opening { in sort() and you have the signature line twice, along with an extra semicolon.

Fix your structural problems and it will compile. No guarantee there aren't any other issues, but this will cure your current problems.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

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