2

For pset3, I have to download pset3.zi and unzip it.

I followed all the steps in the instruction. However, when I get to the program find.c, there's a problem.

The program seems like not working properly. To be clear, this program is provided in the distribution code, not written by me.

As you can see below, the program will look for the number in the command line from a list of numbers I put in when the program is executing.

I put in 15 at the command line and enter 13, 14, 15, 16 for the set of values. So it's supposed to output Found needle in haystack!. However, the program outputs Didn't find needle in haystack. instead.

jharvard@appliance (~/Dropbox/pset3/find): make find
make: `find' is up to date.
jharvard@appliance (~/Dropbox/pset3/find): ./find 15

haystack[0] = 13

haystack[1] = 14

haystack[2] = 15

haystack[3] = 16

haystack[4] =

Didn't find needle in haystack.

jharvard@appliance (~/Dropbox/pset3/find):
5

Have you written the sort and search functions in helpers.c? That is one of the assignments in the problem set. find won't work until you've actually written the code.

As the pset says:

And now the fun begins! Notice that find.c calls search, a function declared in helpers.h. Unfortunately, we forgot to implement that function fully in helpers.c! (To be sure, we could have put the contents of helpers.h and helpers.c in find.c itself. But it’s sometimes better to organize programs into multiple files, especially when some functions are essentially utility functions that might later prove useful to other programs as well, much like those in the CS50 Library.) Take a peek at helpers.c with gedit, and you’ll see that search always returns false, whether or not value is in values. Re-write search in such a way that it uses linear search, returning true if value is in values and false if value is not in values. Take care to return false right away if n isn’t even positive. [emphasis mine]

| improve this answer | |
2

We are not given the source code for search() in helper.c. We are asked to implement this search() function using linear search first then binary search. And since you haven't implemented any of these yet, it will return false (i.e., you will not be able to detect the needle even if it is present in haystack till you code it yourself).

| improve this answer | |

You must log in to answer this question.

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