From: kezman AT nOsPaMbigfoot DOT com (Kieran Farrell) Newsgroups: comp.os.msdos.djgpp Subject: URGENT!!! Please (A Little Long) Message-ID: <3813e85f.18243975@news.pasteur.dialix.com.au> X-Newsreader: Forte Free Agent 1.11/32.235 Organization: DIALix Internet Services Lines: 69 Date: Mon, 25 Oct 1999 05:31:39 GMT NNTP-Posting-Host: 203.12.3.8 X-Complaints-To: abuse AT telstra DOT net X-Trace: nsw.nnrp.telstra.net 940829561 203.12.3.8 (Mon, 25 Oct 1999 15:32:41 EST) NNTP-Posting-Date: Mon, 25 Oct 1999 15:32:41 EST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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. typedef struct StudentTag STUDENT; struct StudentTag { STUDENT *Next; char ID[MAXID]; }; int main(void) { STUDENT *Start = NULL; AddStudent(Start); CleanUp(Start); return 0; } void AddStudent(STUDENT *Student) { STUDENT *New; New = malloc(sizeof(STUDENT)); /* * etc etc. */ Start->Next = New; return; } 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. int main(void) { STUDENT *Start = NULL; Start = AddStudent(Start); CleanUp(Start); return 0; } STUDENT *AddStudent(STUDENT *Student) { STUDENT *New; New = malloc(sizeof(STUDENT)); /* * etc etc. */ Start->Next = New; return (Student); } I think you will all agree ther MUST!!! be a better way, HELP *8) ----- Kieran Farrell