I have made find.c and coded binary search in helpers.c, so when I run find like

./find 42

and start entering sorted values like

haystack[0] = 42

haystack[1] = 43

haystack[2] = 44

haystack[3] = 45

haystack[4] = 46

it runs perfectly. But the EOF(Ctrl + D) is not working. The console screen displays blank screen but it does not return anything.I have to press Ctrl + C to end the program. What the damm hell?

  • Did you make any edits on find.c?
    – kzidane
    Jun 10, 2014 at 6:15

2 Answers 2


Not really sure why this is happening, but the most likely thing that happened is that you've messed up with the main find.c file, as it is, EOF was controlled there itself, so, check to see if it has these linbes of code all right, the const int MAX will be defined at line 22, whereas the rest of the code below originates at line 41(unless the file was edited), if these are present, please provide more details to the problem, like, what keyboard do you use, and if the program doesnt stop when EOF is done, you must see garbage printed out there, whats that ?

    const int MAX = 65536;

    // wait for hay until EOF
    printf("\nhaystack[%d] = ", size);
    int straw = GetInt();
    if (straw == INT_MAX)

Hope this helps.

  • int MAX = 65536; and INT_MAX are unrelated. GetInt() is written such that if it receives no input (ie, because user pressed ctrl-D), it returns INT_MAX rather than an error. INT_MAX is a system constant that is defined in limits.h. In any case, if ctrl-D isn't working, it sounds more like a keyboard problem.
    – curiouskiwi
    Jun 11, 2014 at 22:49

It's hard to find a solution if you don't provide information on how your values are inputed.

If you use scanf() for input, then input -1 to exit the loop.
If you use a file as input, then check the exit clause of your loop (if feof() ).


You must log in to answer this question.

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