0

So, I'm currently stuck on pset3. I'm doing the linear search coding on helpers.c but it doesn't seem to search for the needle in the hay stack. It is behaving quite weird.

If i run ./generate 1000 50 | ./find 127 It returns "Didn't find needle in haystack."

And if i randomly give numbers myself by giving the command ./find 5 then if the number 5 is at the beginning it always returns "Didn't find needle in haystack." but if the number 5 is in the middle somewhere it works fine.

This is my linear search code inside the helpers.c filelinear

And this is the find.c file from where it is called.find

Thanks.

2
  • the values true and false are not the same as TRUE and FALSE. what are you declaring TRUE and FALSE to be?
    – kzidane
    Commented Jun 28, 2015 at 22:26
  • Oh i didn't knew there was a difference between true & True. I just replaced TRUE & FALSE with true & false and the program worked. Can you tell me what is the difference between the 2? Thanks a lot. Commented Jun 29, 2015 at 10:00

1 Answer 1

0

as you might recall from the first lectures, the C language is case-sensitive. the defined constant true (defined in stdbool.h which is included by cs50.h) is not the same as TRUE. similarly, the defined constant false (defined in stdbool.h as well) is not the same as FALSE.

unless you have TRUE and FALSE each defined to be some value, you'll get a compilation error.

You must log in to answer this question.

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