0

I have just implemented binary search on helpers.c and it compiles perfectly, but, when I try to execute find, the program doesn't quit. I tried with ./generate 3 2 | ./find 59797 (because 59797 is one of the numbers on ./generate 3 2), but I always get this:

haystack[0] =

haystack[1] =

haystack[2] =

haystack[3] =

and the programs doesn't give me an output or something, it just stays there until I hit ctrl C. I figured it may be the while loop in the beginning of my code, which is (won't post whole code for academic purposes):

while (values > 0)

{
 ...
}

PS: at the end of the program (outside the while loop) there is a return false in case nothing in my while loop works.

I looked through pretty much every similar question in here but nothing helped. Does anyone know what to do?

1

The "haystack[0] = " is because that is being printed to the screen by the program but the input is being taken from the pipe from ./generate. The numbers generated won't be printed to the screen. In other words, that part is behaving normally and as expected.

Your program looks to be moving into an infinite loop. From what little you posted, it looks like the reason is pretty straightforward. The while loop will keep executing until values is less than or equal to 0. ( What is values declared as? Isn't values an array? ) In any case, something inside the while loop has to change values to something less than or equal to 0, or you need a different test.

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

You must log in to answer this question.

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