LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Function Level Hierarchy (http://www.linuxquestions.org/questions/programming-9/function-level-hierarchy-386902/)

Mistro116@yahoo.com 11-27-2005 02:05 AM

Function Level Hierarchy
 
Hello,

I have another hierarchy question, but this time it is a little different.

I am working on a program with dynamic memory allocation and so forth, and from my previous post, (Two Dimensional Array of Characters), I am working with some functions that deal with generating a two-dimensional array of letters and generating an array of structure of words.

I want to use other functions in this program, such as GenerateSearchResults (...) and RecursiveSearchList (...)

HOWEVER:

I want to design my main in the following way to be a "skeleton" of the program:

GenerateLetters(...)
GenerateWords(...)
RecursiveSearch(...)
GenerateSearchResults(...)

However, it seems once I call GenerateLetters and GenerateWords, I have no way to access the two-dimensional array of letters or the array of structures, which are both needed for the other two functions in my main.

How can I eliminate this hierarchy problem.

Thanks,

Mistro116

AdaHacker 11-27-2005 11:12 AM

This question makes no sense. How can you not have a way to access the arrays you generate? Didn't you return pointers to the arrays from GenerateLetters() and GenerateWords() so that you could access them? Or do the same kind of thing with reference parameters or even (ugh) global variables? I don't understand what your problem is.

Mistro116@yahoo.com 11-27-2005 11:52 AM

Well... I could do that, but I have a problem returning both the array of words and the number of words in one function, since it is a structure. Also, how do you return a pointer to a two-dimensional array?

Mistro116

AdaHacker 11-27-2005 03:42 PM

Quote:

Originally posted by Mistro116@yahoo.com
Well... I could do that, but I have a problem returning both the array of words and the number of words in one function, since it is a structure.
The most common way to handle that is to return the number of words and use a reference parameter for the array.

Quote:

Also, how do you return a pointer to a two-dimensional array?
The same way you return a pointer to a one-dimensional array. The only difference is that you'd declare the return type as a pointer to a pointer, e.g. if char* is a 1-D array of characters, char** is a 2-D array.

Mistro116@yahoo.com 11-27-2005 04:30 PM

Thanks AdaHacker, I've designed a way to perform what I want based on your advice.

Much obliged,

Mistro116


All times are GMT -5. The time now is 03:03 PM.