0

Please help, I'm not sure how to resolve these two errors, I kinda understand what they're saying but not entirely sure how to fix them. Below is part of my code (as recently learned that I shouldn't post the whole code here) and then the errors. Many thanks

// Swap function
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}

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

// TODO: implement an O(n^2) sorting algorithm

for(int i = 0; i < n; i++)
   {
    for (int j = i+1; j < n; j++)
        {
            if (values[i] > values[j])
            swap (&values[i], &values[j]);

        else 
        break;
    }

}

return 0;
}

These are the errors (by the way c:50:5 is referring to the first line of code above):

helpers.c:50:5: error: function definition is not allowed here
    {
    ^
helpers.c:59:31: error: expected ';' at end of declaration
void sort(int values[], int n)
                              ^
                              ;

I would really appreciate some insight, many thanks

1
  • Oh, by the way I have tried to remove the '{' from c:50 however that just increases the erros and kinda messes up my swap function. And am I allowed to use this swap function as it was shown to us in week 3's lecture? Thanks – Sofia Jan 25 '17 at 18:38
1

Go through your code and make sure all your {...} bracket pairs are in the correct place. I can see straight way that you're missing one in your sort function, not to mention what may be happening in the code you haven't shown. I think, based on the last question you posted, that the compiler thinks you're trying to declare the swap function inside another function.

You must log in to answer this question.

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