0

I may be making too much of this but I have the 2 routines working. Now I want to combine into helpers.

I can't make them since they wont have main and variable declarations any more.

What to do? I have fifteen done and am stuck here. Please let me in on the secret sauce.

Thanks

2
  • Henry, can you clarify, please? Where (in which .c file(s)) are the two routines that are working? – DinoCoderSaurus Oct 31 '15 at 22:25
  • Sorry, I should have more explicit. They are search and a bubble sort routine. – Henry K Staub Nov 2 '15 at 6:37
0

It looks like you have misunderstood, or not understood how source code files are combined and compiled into an executable file. The sort() and search() functions - two independent and self-contained functions that you write - are supposed to be placed inside of helpers.c while main() exists already in find.c. You should open find.c and review the contents.

The Makefile contains the various instructions on how to build and compile the executable file. Most important is the followiing line in Makefile:

find: find.c helpers.c helpers.h

It tells the compiler to use all 3 of these *.c and *.h files in combination to build the executable file find.

BTW, you don't make helpers, you make find.

Perhaps you would benefit from a review of all the class material and videos on 'make', functions structure, and program compiling.

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

6
  • Thanks very much. I am aware that the subroutines are going to be called by find. At issue or my befuddlement is that I read somewhere that I have to inclued prototypes of search and sort at the begging of the calling program, in this case find.c. Would you like to comment on this please? – Henry K Staub Nov 3 '15 at 6:12
  • That is one way to handle prototype placement. Prototypes are placed in the program sequence somewhere before any calls to the function, or the function code itself must appear. However, the program instructions say not to alter find.c. The prototypes for search and sort have already been placed in helpers.h (or they should be). Also, remember that the prototypes for both cannot be changed. – Cliff B Nov 3 '15 at 6:36
  • With regards to find, the code supplied keeps asking for a straw. I am wondering about the ./generate 1000 | ./find 127 example. I got the idea that gererate as going to fill array[] with values. This is wrong because find keeps asking for straw, no doubt. Why was it done this way instead of generating the array and asking it to find a value. I have a working program that does search and finds a value. I am trying to reconcile the prohibition of not changing find.. Sorry I am doing this online and you guys are the only source I have. Please comment and thanks. – Henry K Staub Nov 3 '15 at 19:09
  • This class has many hidden lessons. This one is working in a team programming environment . Some people are given certain parts to work on. Most commonly, people will be given the job of writing a function that must accept certain parameters and must return a specific result. This is what is going on. You're being given the job of writing search and sort. Another team has already written the rest of the code. If everyone on a team could go around changing parts that others are writing, it's just chaos. I was on a team that tried this, it was really ugly! That's the lesson. (continues....) – Cliff B Nov 3 '15 at 19:15
  • RE: generate|find. This is called piping the results of one program to another as input. The operating system calls both programs, and sends, or pipes, the results of generate into find as input. When it does, find is still going to display the prompts for more input as it goes, but it won't display the numbers that are piped through. generate isn't actually populating the array, it's providing the numbers to find (without displaying them) and find is taking those numbers as if they were typed in the terminal window and processing them. That's what you are seeing. – Cliff B Nov 3 '15 at 19:20

You must log in to answer this question.

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