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