delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/05/17/13:31:13

Date: Fri, 17 May 2002 20:27:04 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <3395-Fri17May2002202704+0300-eliz@is.elta.co.il>
X-Mailer: emacs 21.2.50 (via feedmail 8 I) and Blat ver 1.8.9
In-reply-to: <ac39ir$m9gr2$1@ID-106847.news.dfncis.de> (noone@knowhere.com)
Subject: Re: Static variables
References: <ac39ir$m9gr2$1 AT ID-106847 DOT news DOT dfncis DOT de>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019