Mail Archives: djgpp/2002/05/17/13:31:13
> From: "Matthew Bayliss" <noone AT knowhere DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Fri, 17 May 2002 17:03:03 +0100
>
> If you break on line 117 and "print words_ptr" the pointer has an
> assignment. When the function returns to main() (line 31) the variable has
> no value.
That's because C passes variables by value; if you want to change the
variable's value, you need to pass its address.
In this case, you want `inputdata' to change the value of the variable
words_ptr, so you need to pass its address, like this:
if ( inputdata( &words_ptr ) == 0 ) // Read the data in.
Of course, the function's prototype should also change:
int inputdata( struct wordstruct **words_ptr ); // Function to read words
And the code of `inputdata' should change accordingly as well.
- Raw text -