Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!news.cs.indiana.edu!arizona.edu!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: dumb VAXC question about -> operator: what's Message-ID: <1144@caslon.cs.arizona.edu> Date: 12 Mar 91 16:09:06 GMT References: <1991Mar12.150609.4814@athena.mit.edu> Distribution: na Organization: U of Arizona CS Dept, Tucson Lines: 35 In article <1991Mar12.150609.4814@athena.mit.edu> seaotter@athena.mit.edu (Stace: the Final Frontier) writes: > >int init_data(data *p_data) ^^^^^^^^^^^^ >{ > p_data = (data *) malloc (sizeof (data)); >[...] >} >[...] > main (int argc, char *argv[]) > { > /* other variables ... */ > > data *p_data; > > if (init_data(p_data) == ERROR) { ^^^^^^ >[...] Your problem is that you don't seem to understand how to do call-by-reference in C. In order to get p_data to change in init_data(), you have to pass its *address*, not just its value. So you need to change the call to init_data(&p_data) change the declaration to int init_data( data **p_data ) and change the initialization to *p_data = malloc( sizeof(data) ) You probably also need to re-read the chapter in your text on pointers and the chapter on function parameters. -- Dave Schaumann | dave@cs.arizona.edu | Short .sig's rule!