O aout core find generate this target allows you to

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n INT_MAX, a constant that, per find.c, will compel find to stop prompting for hay. The program will then look for that needle in the hay you provided, ultimately reporting whether the former was found in the latter. In short, this program searches an array for some value. In turns out you can automate this process of providing hay, though, by “piping” the output of generate into find as input. For instance, the command below passes 1,024 pseudorandom numbers to find, which then searches those values for 13. ./generate 1024 | ./find 13 Alternatively, you can “redirect” generate’s output to a file with a command like the below. ./generate 1024 > numbers.txt 5 < 13 This is CS50. Harvard College Fall 2010 You can then redirect that file’s contents as input to find with the command below. ./find 13 < numbers.txt Let’s finish looking at that Makefile. Notice the line below. all: find generate This target implies that you can build both generate and find simply by executing the below. make all Even better, the below is equivalent (because make builds a Makefile’s first target by default). make If only you could whittle this whole problem set down to a single command! Finally, notice these last lines in Makefile: clean: rm -f *.o a.out core find generate This target allows you to delete all files ending in .o or called a.out, core (tsk, tsk), find, or generate simply by executing the command below. make clean Be careful not to add, say, *.c to that last line in Makefile! (Why?) Any line, incidentally, that begins with # is just a comment. And now the fun begins! Notice that find.c calls sort, a function declared in helpers.h. Unfortunately, we forgot to implement that function fully in helpers.c! Take a peek at helpers.c with Nano, and you’ll see that sort returns immediately, even though find’s main function does pass it an actual array. 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 (e.g., sort) are essentially utility functions that might later prove useful to other programs as well, much like those in the CS50 Library. Incidentally, recall the syntax for declaring an array. Not only do you specify the array’s type, you also specify its size...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online