A needle in the haystack

Could any one tell me how to terminate the program in this problem

I think you need to scan till EOF (end of file);
You can use something like this:




// Rest of your code starts here


1 Like

Thanks a lot problem solved !!!

But when i type this scanf("%d",&needle_length)!=EOF the program keeps on running in my cmd even after the EOF

Just give inputs in a test file and try again (Redirect this file to the executable generated after compilation). If you are a LINUX user, you can do simply like this :

“./a.out < test.in” . Here “a.out” is executible and test.in contains your test cases.