I'm just wondering the best way to test out sort and search in helpers.c. Since the file won't compile/run on its own, how can I test the code that I'm writing?


Well, helper.c is part of the program named find, you may run

make find

which, per the Makefile, will compile both, find.c and helpers.c. You may then run

./find <some value>

and provide it with your values to test the searching/sorting functionality.

| improve this answer | |
  • Kareen, how would you test sort in this way? Nothing prints out except that you found the needle or not. – Azurespot Aug 22 '14 at 8:56
  • @NoniA. you could write some code for printing the sorted array in helpers.c! – Kareem Aug 22 '14 at 9:09
  • That's what I don't know how to do though :( I tried to print my minimum variable at the end of my inner loop, each time it loops, but it gives values that don't make sense. – Azurespot Aug 23 '14 at 23:27
  • 1
    @NoniA.well, the writer of this program assumed that the user can input a maximum of MAX integers (i.e., 65536) and this definitely has some reasons one of which is that we can't let the user input an infinite number of integers since we have a finite memory. If the user inputs, say 10 integers, definitely we don't want to care about the latter 65526 elements in haystack. Here comes the role of n which is the number of integers that were inputted by the user or, in other words, the number of integers we care about. – Kareem Aug 24 '14 at 22:20
  • 1
    @NoniA. when size is passed in to search(), it matches the place of n (i.e., the parameter of search()), a copy of the value that's stored in size is stored in n. Recall that size represents the number of integers that were inputted by the user (and so does n). Given these information, we can print the first n elements of values[] using a simple for loop. – Kareem Aug 24 '14 at 22:21

You must log in to answer this question.

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