TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: BOGDAN SHEPTUNOV
date: 1997-12-21 10:43:00
subject: how should I return pointer to string?

Hello All.
I need implement method which should read a string from configuration file
and return a part og this string, such as:
"Server port number: 101"
method should return "101".
Code looks like this:
char*
IniFile::readLine(void)
{
  char buffer[NAME_MAX_LENGTH];
  char *_value;
  while (!_iniFile.eof())
  {
      // read line
      _iniFile.getline(buffer, NAME_MAX_LENGTH);
      if (strstr(buffer, "Server port name:") == NULL) continue;
      _value = strchr(buffer,":");
      _value++;
      return _value;
   }
   // nothing found - return 0
   return 0;
}
A problem is here: in readline(void) _value is OK. I mean it points to the
correct line. But when "return" is called "buffer" is being destructed,
and the result of the call
 char* result = readLine()
is something incredible.
Help me please  :-)
Bogdan
--- GoldEd 2.50+ метра
---------------
* Origin: Crematory (2:463/285.82)

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