home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!ub4b!mble.philips.be!stern
- From: stern@mble.philips.be
- Newsgroups: comp.lang.c
- Subject: Re: Is it MY problem...or is it Borland's?
- Message-ID: <1992Jul27.092039.190@mble.philips.be>
- Date: 27 Jul 92 09:20:39 MEWT
- References: <1992Jul25.162844.18778@uwm.edu>
- Organization: MBLE , Brussels, Belgium
- Lines: 40
-
- In article <1992Jul25.162844.18778@uwm.edu>, rca@csd4.csd.uwm.edu (Robert C Allender) writes:
- > I'm VERY new to C, but I can usually hold my own by R(ing)TFM. This is
- > different. I've checked through Borland's FAX document catalog (I use
- > Borland's C++ 3.0, but I use the standard C mode), ALL the manuals, a few
- > 3rd party books on Borland C ... nothing. Here's the problem:
- > I initialize a char * in main() and pass it to a function that gets a string,
- > passing the address of the string back to main(). If I try to print the
- > string back at main(), it works. I pass the char * to the next function, and
- > I can print the string at the beginning of that function, but by the end of
- > it, the string is garbage. If I then pass the value to main() and send it to
- > yet aother function, the array is empty. I can put checks in anywhere and
- > find the strlen() to be correct at ANY of the points where it won't print,
- > but the values get corrupt and then dissappear. What am I doing wrong?
- >
- > Here's the boiled-down code...
-
- [deleted]
-
- > char * scrollbox(char,int,int);
-
- [deleted]
-
- > main() {
- > char drive, *c;
- > c = scrollbox(drive,61,10); <---- This gets a directory, etc.
- >
- > clear_half(c); <-- can print the array here BEFORE the end
- > of the function, else it's garbage.
-
- This is a bug in your program:
-
- As the string containing the directory is local to function scrollbox,
- it is located on the stack. If you access it immediately after calling
- the function there are many chances that this value has not been modified
- (it is obviously a non-standard side-effect); this is what happens here.
- Once you call another function the stack is overwritten.
-
- That's all folks
-
- -- Marc Stern <stern@mble.philips.be>
-