LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-27-2005, 02:05 AM   #1
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Rep: Reputation: 15
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
 
Old 11-27-2005, 11:12 AM   #2
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
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.
 
Old 11-27-2005, 11:52 AM   #3
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Original Poster
Rep: Reputation: 15
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
 
Old 11-27-2005, 03:42 PM   #4
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
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.
 
Old 11-27-2005, 04:30 PM   #5
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Original Poster
Rep: Reputation: 15
Thanks AdaHacker, I've designed a way to perform what I want based on your advice.

Much obliged,

Mistro116
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#include hierarchy Mistro116@yahoo.com Programming 2 11-27-2005 11:50 AM
where to store mp3 in file hierarchy leopardb Linux - Newbie 6 07-05-2005 09:40 AM
Creating a group hierarchy? statuszero Linux - Security 5 07-16-2004 03:18 PM
Desktop hierarchy filesystem: I WANT TO CHANGE IT!! opioid Linux - Software 2 03-28-2004 01:32 AM
Filesystem Hierarchy Question - You probably get these alot. Sorry :( JoeLinux Linux - Newbie 4 04-23-2002 09:33 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration