0

First, thank you for your time. I am working on pset3. I don't know why my code does not work. I also have some questions: 1. Do I need a main function? I mean, do i need main to call the functions? 2. Do i need to modify find.c?

Here is my code:

Helper.c:

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

void sort(int values[], int n)
{
    for (int i = 0; i < n; i++)
    {
        int element = values[i];
        int j = i;
        while (j > 0 && values[i - 1] > element)
        {
            values[j] = values [j - 1];
            j = j - 1;
            values[j] =element;
        }
    }
5

In this pset, the file find.c has the statement #include "helpers.h" which will cause helpers.c to be incorporated into the final executable program find. The file find.c has main, so no, you don't need main in helpers.c.

Your code has a number of syntax errors, something that that programmers will constantly get, but it will be less and less with practice and experience. First, you don't need prototypes in this file, they're in helpers.h (or should be.) Next, prototypes end with a semicolon ; but the actual function should not have a semicolon before the curly brace that starts the function's code body.

FOR statements need a closing ) before the curly braces.

Finally, I've always found it best to fix compiler errors in order. Often, fixing one error eliminates later errors that are caused by the earlier one. Pay attention to the compiler errors. In most cases, they point at and describe exactly what is wrong, or at least which element is causing the problem.

That should get you started. Fix all the syntax issues so that it compiles and then you can start on the logic problems.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

| improve this answer | |

You must log in to answer this question.

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