473,545 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ar ray[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 2488
beetle <be****@beetlem ail.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(ar ray[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***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #2
On 24 Jan 2005 20:26:26 GMT, Je***********@p hysik.fu-berlin.de wrote:
beetle <be****@beetlem ail.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
13738
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
2102
by: Ole | last post by:
hello, Little problem: struct operatable { char * operatable_id; int ( * delegate ) ( ... ); somedatatype data; };
4
1267
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
2403
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 following: unsigned short image; typedef struct{ unsigned short** img_ptr; unsigned short img_width; unsigned short img_height;
5
2835
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 instead od struct and fixed statement to get a pointer, it seemed to work, but i bet there is a better and more elegant way to do that and a second...
2
2495
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> main(argc, argv) int argc;
5
7803
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 EAGAIN/EINTR), I've written a wrapper function (full source code on the bottom) to call those functions and just pass the function pointer to it: ...
2
17755
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
2557
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 struct(local_train) which carries the firstblock and last block address of a double linked list(-wagon-wagon-wagon-) which carries points of structs(train_load)...
0
1049
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. I want to call the win32 function from C# and pass it a ref to a struct of virtual functions - just as I would from win32 C. For example, I'm...
0
7416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7442
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7776
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1905
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.