-=>Quoting Kurt Kuzba to Bogdan Sheptunov <=-
BS>Code looks like this:
BS>char*
BS>IniFile::readLine(void)
BS>{
BS> char buffer[NAME_MAX_LENGTH];
BS> char *_value;
BS> while (!_iniFile.eof())
BS> {
BS> // read line
BS> _iniFile.getline(buffer, NAME_MAX_LENGTH);
BS> if (strstr(buffer, "Server port name:") == NULL) continue;
BS> _value = strchr(buffer,":");
BS> _value++;
BS> return _value;
BS> }
BS> // nothing found - return 0
BS> return 0;
BS>}
KK>You are returning a pointer to a string which no longer
KK>exists once you exit the function.
Actually, the pointer *exists*, but the stack frame probably is
clobbered. The result is the same, no string.
KK>You must either use a static, a global, allocated, or a class
KK>variable. Since this IS a class function, you should probably just
KK>put a pointer in your private data,...
I would allocate some space from the heap and delete it when done.
Or, I would declare a global string area.
That's my two-cents. [grin]
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 530-893-8079 * (1:119/88)
|