473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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...!
Nov 14 '05 #1
2 2475
beetle <be****@beetlemail.com> 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 ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
On 24 Jan 2005 20:26:26 GMT, Je***********@physik.fu-berlin.de wrote:
beetle <be****@beetlemail.com> 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
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pushkar Pradhan | last post by:
I need to pass a struct by reference to a function: The struct: typedef struct tifftags { uint32 imageWidth, ...; ... } TIFFTAGS; typedef TIFFTAGS * TIFFTAGS_PTR; main() { .....
4
by: Ole | last post by:
hello, Little problem: struct operatable { char * operatable_id; int ( * delegate ) ( ... ); somedatatype data; };
4
by: QQ | last post by:
Here is my program the head is typedef struct struct_CN { unsigned char magicA; unsigned char magicB; unsigned short msgLen; } CN;
5
by: Mark Feller | last post by:
I have an embedded application where malloc( ) is not available. So I declare images as globals, but want to be able to pass image information including a pointer in a structure, as in the...
5
by: adrin | last post by:
hi i have the following problem: i use functions from an external dll(normal w32 unmanaged library) which takes a structure address as an argument.. how do i pass it in c#? i tried using array...
2
by: jconnort | last post by:
I'm trying to write a function to get the current system time, so I can use it when I need to output it to a log, below is the code I'm testing: #include "include.h" #include <stdlib.h> ...
5
by: A. Farber | last post by:
Hello, I call readv() and writev() in several spots of a program which I run under Linux, OpenBSD and Cygwin. Since it always the same way (check the return value; then check errno and retry if...
2
by: nano2 | last post by:
Hi, Have the following scenario in C. returning a copy of the structure which is not good should be passing back a structure pointer How would i acahieve this . any ideas..
9
by: dreiko466 | last post by:
(sorry about my english) Hello, i am a newbie in C and i am trying to understand how to use free(...) and malloc(...) functions. In the following programm i successfully create a point of...
0
by: =?Utf-8?B?Uk9MU1Q1?= | last post by:
I have a native win32 C++ DLL that has exported functions (I can't modify the win32 DLL). One of these exported functions needs a pointer to a structure. The structure contains virtual functions. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.