Is someone experiencing the same as I do? I finsihed my code for the search and sort case and half of the times my program crashes (unfinite loop(?)) while running. After a lot of debugging attempts I saw that the program stopped in the find.c file (which is given by CS50) on line 52 (printf("\n"). I checked this by writing a simple printf function on line 53 (so no } or { are in between). This check isn't written down in the cases my program crashes. To fix this I redownloaded the zip file and had rewritten my code, to be sure that I didn't change anything in the find.c file, but that didn't help.

The exact problem is this: when I run for instance ./generate 8 8 | ./find x. The program crashes (just a blinking prompt) when x is the 2nd, 4th, 7nd and 8th number that is generate through ./generate 8 8. Besides that some random numbers that aren't in the listed are resulting in: Needle not found and some return this crash as well.

Is there anyone who has experienced this problem as well and knows how to fix it? and is there another way to check my written code than through gedit/ the cs50 check."code"?

2 Answers 2


find.c has been very stable, so I'm confident that the problem isn't there. It sounds more like you are experiencing infinite loops and not program crashes. I'm also highly suspicious that the problem lies in your sort function, since it is the very next call in find.c, and based on your description of the behavior.

I would look for the possibility of accessing invalid memory locations, infinite loops, or anything else that is breaking the sort. For testing purposes, you might also write out a routine to print out the sorted list and put it at the end of the load routine.

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

  • Thanks for your answer! At first I obviously thought that it was my code, however my check (with a printf) between line 52 in the find.c file and the line which calls the sorted function in helpers.c, isnt printing as well. Therefore I thought that it might is something in find.c. Nevertheless I'll check my sorted function again tonight (Europe) and see if that fixes this infinite loop, otherwise I will post some of my code of both the find.c and helpers.c file. Commented Oct 16, 2015 at 6:38
  • Try putting unique printf statements before, inside and after the various loops in your sort and search functions. Also, did you put a \n in your printf() statements? I've noticed that frequently, when this isn't done, the print statement won't execute when there's an issue. ( don't know why though. )
    – Cliff B
    Commented Oct 16, 2015 at 15:35
  • Okay, I found the answer, but I'm not quite sure how I did it! There was indeed an infinite loop in my sort loop, but again I printed before this function was called some printf's, that didn't appear. It is still unknown to me why these didn't print out. Thanks for the input and help on this problem! Commented Oct 21, 2015 at 14:21

find.c doesn't have any issues. So, I guess the issue is in one of your functions, which has an infinite loop. Have you tried using gdb?

  • Thanks for your answer! It most definitely seems like an infinite loop, but the exact location of this loop is a bit suspicious to me (see comment on other answer). I tried GDB, but I couldn't figure out how to use it over multiple files (generate.c and find.c) which have all their own command line arguments. I want to check the program with my example of: ./generate 8 8 | ./find 257 Commented Oct 16, 2015 at 6:45

You must log in to answer this question.

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