0

I started changing "helpers.h" to implement a linear search. I have not changed generate.c or find.c.

#include <cs50.h>

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

    else
    {
        return false;
    }
  }
}

When I try to make find, I get the following error:

$ make find
clang -ggdb3 -O0 -std=c11 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
In file included from find.c:19:
./helpers.h:18:1: error: expected identifier or '('
{
^
1 error generated.
In file included from helpers.c:12:
./helpers.h:18:1: error: expected identifier or '('
{
^
1 error generated.
make: *** [find] Error 1

It appears to be a problem in the helpers file, but I can't for the life of me figure out what is the problem. I thought it might be that the curly ones after "bool" were extraneous, but then it gives the same error for the curly brace after 'for', and that one is not extraneous. I feel like I'm missing something obvious.

0
 bool search(int value, int values[], int n);

Do you think that the semicolon at the end of this line might have something to do with it? ;-)

Also, the code above should be in helpers.c, not helpers.h. It is unclear from your comments which file this code is in (I think it's the .c file), but code that actually does processing should not be placed in a header file.

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

3
  • The code was in headers.h (I've now moved it to headers.c and am getting a different error). – K. Rich Feb 18 '17 at 20:02
  • Have you dealt with that semicolon yet? It disconnects the code that follows from the signature line, thus orphaning the code and the compiler doesn't like that. – Cliff B Feb 18 '17 at 23:12
  • Yes, that fixed the problem! After that, I got an unrelated issue due to the fact that I was running "make headers" when I should have been running "make find." I've managed to make the searching work. Thanks! – K. Rich Feb 19 '17 at 3:08

You must log in to answer this question.

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