dave@cs.arizona.edu (Dave P. Schaumann) (03/13/91)
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!