0

will not compile with or without ; at the end of the statement void sort(int values[], int n).

Clang errors and my helpers file are given below.

Error message with ;

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

Error message without ;

jharvard@appliance (~/Dropbox/pset3/find): make find
clang -ggdb3 -O0 -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
helpers.c:33:39: error: expected ';' at end of declaration
        void sort(int values[], int n)
                                      ^
                                      ;
/**
 * helpers.c
 *
 * Computer Science 50
 * Problem Set 3
 *
 * Helper functions for Problem Set 3.
 */

#include <cs50.h>
#include "helpers.h"

// TODO: implement a searching algorithm
/**
 * Returns true if value is in array of n values, else false.
 */
bool search(int value, int values[], int n)
{
    for(int i=0; i<n;i++)
    {

        if (values[i] == value)
            return true;
    }
    return false;

// TODO: implement an O(n^2) sorting algorithm
/**
 * Sorts array of n values.
 */
void sort(int values[], int n)

    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  false ;
    }
}

uma1966

0

You have a mismatch of curly braces. Although you have the right number, they're in the wrong places. You are missing the closing curly brace for the search function, making the signature of the sort function look like a call to sort instead.

Next, you have a couple of issues with curly braces in the sort function itself. I'll leave it to you to 'sort them out' (pun intended), as it will be a good learning experience. ;-)

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

10
  • In addition to @Cliff_B answer, I formatted the code to make it easier to see where the misplaced curly braces are. If you keep the style of your code in good shape while you write new code, it will be easier to see those kind of typos.
    – ChrisG
    Aug 24 '15 at 18:11
  • @Cliff Bjharvard@appliance (~/Dropbox/pset3/find): check50 2014.fall.pset3.find helpers.c Checking........................................................................:) helpers.c exists :) helpers.c compiles :) finds 42 in {42,43,44} :) finds 42 in {41,42,43} :) finds 42 in {40,41,42} :) finds 42 in {41,42,43,44} :) finds 42 in {40,41,42,43} :) finds 42 in {39,40,41,42} :) doesn't find 42 in {39,40,41} :) doesn't find 42 in {39,40,41,43} sandbox.cs50.net/checks/dfcf489d2185484885eef5c859bae758 jharvard@appliance (~/Dropbox/pset3/find).
    – uma1966
    Aug 24 '15 at 20:28
  • @Cliff B. Thanks very much.This error was driving me crazy. I tested with other examples in the notes with numbers 127 and 128 and I got correct answers. Only with 42 I did not find it when I used the command ./generate 1000 . I am not sure whether this number is there in the pseudo random numbers generated by the computer. uma1966
    – uma1966
    Aug 24 '15 at 20:32
  • @Cliff BI know how to preserve the format of gedit files. How do you keep the format of the Clang output,when we want to copy them into the cs50 Stack.Uma1966
    – uma1966
    Aug 24 '15 at 21:54
  • check50 is behaving erratically.With the same files that were passing all its tests I am getting the following message
    – uma1966
    Aug 26 '15 at 3:49

You must log in to answer this question.

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