TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT KUZBA
from: TIM HUTZLER
date: 1997-12-30 14:39:00
subject: Re: how should I return

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

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