TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BOGDAN SHEPTUNOV
from: KURT KUZBA
date: 1997-12-27 13:05:00
subject: how should I return point

BS> Code looks like this:
BS> char*
BS> IniFile::readLine(void)
BS> {
BS>   char buffer[NAME_MAX_LENGTH];
BS>   char *_value;
BS>
BS>   while (!_iniFile.eof())
BS>   {
BS>       // read line
BS>       _iniFile.getline(buffer, NAME_MAX_LENGTH);
BS>
BS>       if (strstr(buffer, "Server port name:") == NULL) continue;
BS>
BS>       _value = strchr(buffer,":");
BS>       _value++;
BS>       return _value;
BS>    }
BS>    // nothing found - return 0
BS>    return 0;
BS> }
   You are returning a pointer to a string which no longer
   exists once you exit the function. You must either use a
   static, a global, allocated, or a class variable.
   Since this IS a class function, you should probably just
   put a pointer in your private data, initialize it to NULL
   in the constructor, and test on each use, calling delete
   if it already points to something, and redefining it with
   new to hold the current info. Test it again in your
   destructor, and call delete if it is not NULL, to clean
   up any possible memory leaks. Now you are working with
   something stable and reliable that will be there after
   you return from the function call. If you know for certain
   the upper limit of characters you will require, then you
   might just place an array of type char in your class and
   use that instead of dynamic allocation.
> ] Wait a minute... ///\oo/\\\ Almonds don't have legs.........
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.