From: DavMac AT iname DOT com (Davin McCall) Newsgroups: comp.os.msdos.djgpp Subject: Re: URGENT!!! Please (A Little Long) Date: Mon, 25 Oct 1999 11:44:03 GMT Organization: Monash Uni Lines: 52 Distribution: world Message-ID: <38144199.45282766@newsserver.cc.monash.edu.au> References: <3813e85f DOT 18243975 AT news DOT pasteur DOT dialix DOT com DOT au> NNTP-Posting-Host: damcc5.halls.monash.edu.au X-Trace: towncrier.cc.monash.edu.au 940851814 25095 130.194.198.138 (25 Oct 1999 11:43:34 GMT) X-Complaints-To: abuse AT monash DOT edu DOT au NNTP-Posting-Date: 25 Oct 1999 11:43:34 GMT X-Newsreader: Forte Free Agent 1.1/32.230 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Mon, 25 Oct 1999 05:31:39 GMT, kezman AT nOsPaMbigfoot DOT com (Kieran Farrell) wrote: >Heya peeps, > >I need a liitle help, I am doing a complex flat file database using >linked lists and I can't think for some reason. Please look at the >following segment. [snipped] >OK this is the sort of thing I'm trying to do, however when I allocate >memory and leave the function it destroys the memory and Start in main >is still NULL. This suggests to me that I'm passing by value and not >by reference right? > >So how would I pass the pointer to the structure by refference. As a >quick fix I have done the following. [snipped again] To pass a pointer by reference, you pass a pointer to the pointer. For eg (and this isn't tested): --- begin #include void AllocInt( int **x ) { *x = malloc(sizeof(int)); /* allocate space for an int */ **x = 5; /* set the value to 5 */ } int main() { int *a; AllocInt(&a); printf( "*a is: %d\n", *a ); return 0; } --- end Hope this helps. Structures are a little more complex as you have to do stuff like (*myvar)->member = .... Davin. __________________________________________________________ *** davmac - sharkin'!! davmac AT iname DOT com *** my programming page: http://yoyo.cc.monash.edu.au/~davmac/