Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > passing pointer->struct->pointer->struct to function. .. ??

Reply
Thread Tools

passing pointer->struct->pointer->struct to function. .. ??

 
 
beetle
Guest
Posts: n/a
 
      01-24-2005
Hello,

I'm storing data in several different binary tree's.

The root node is located in a struct containing general data about the
tree.

struct lnode {
char *fname;
int nentry;

struct tnode *root;
};

struct tnode {
char *data;
int pos;

struct tnode *left, *right;
};

Now, how do I pass the binary tree root to a function since it's
located in another struct ?

For example this doesn't work
array[count]->root = tnode_insert(array[count]->root, data);

where array is a dynamic list of ptr's to lnode structs.

Ehmm.. actually I have another question now I am at it..
What's the best to init a struct containing different data-types to
zero ? Is it:
struct lnode *bla = {0};
or
struct lnode *bla = NULL;

Thnkx a lot...!
 
Reply With Quote
 
 
 
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      01-24-2005
beetle <(E-Mail Removed)> wrote:
> I'm storing data in several different binary tree's.
> The root node is located in a struct containing general data about the
> tree.


> struct lnode {
> char *fname;
> int nentry;
> struct tnode *root;
> };


> struct tnode {
> char *data;
> int pos;
> struct tnode *left, *right;
> };


> Now, how do I pass the binary tree root to a function since it's
> located in another struct ?


> For example this doesn't work
> array[count]->root = tnode_insert(array[count]->root, data);


> where array is a dynamic list of ptr's to lnode structs.


If 'array' is an array (dynamic or not dynamic) of structures (and not
an array of pointers to structures) and you want to pass the value of
the 'root' pointer element of the element numbered 'count' you need

array[ count ].root = tnode_insert( array[ count ].root, data );

You would use "array[ count ]->root" only if "array[ count ]" is a
pointer to a structure.

> Ehmm.. actually I have another question now I am at it..
> What's the best to init a struct containing different data-types to
> zero ? Is it:
> struct lnode *bla = {0};
> or
> struct lnode *bla = NULL;


Since you're not initializing a structure here but a pointer to a
structure the second alternative looks is correct. If you want to
initialize a structure you would probably use

struct lnode bla = { NULL, 0, NULL };

but

struct lnode bla = { 0 };

would also do.
Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
 
 
 
beetle
Guest
Posts: n/a
 
      01-25-2005
On 24 Jan 2005 20:26:26 GMT, (E-Mail Removed)-berlin.de wrote:

> beetle <(E-Mail Removed)> wrote:
> > I'm storing data in several different binary tree's.
> > The root node is located in a struct containing general data about the
> > tree.


roger.. thnkx.... !

B
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array from FORTRAN to C then passing it within C andReturning it to FORTRAN deadpickle C Programming 1 11-07-2010 02:38 PM
Passing parameters to an executable vs. passing them to a server Ramon F Herrera C++ 8 09-13-2009 02:48 AM
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
Passing by const & and returning a temp vs passing by value and returningit Victor Bazarov C++ 25 03-23-2005 04:24 PM



Advertisments