Re: Returning a CHAR[] from a function
- From: "Vipin" <Vipin@xxxxxxxxxx>
- Date: Sun, 27 Aug 2006 09:35:33 +0530
If you change "char buffer[_MAX_PATH];" to
"static char buffer[_MAX_PATH];" you will be fine because static variable's
lifetime is for the entire duration of the program. The recommeded way is to
return a string or a CString.
--
Vipin Aravind
http://www.explorewindows.com/Blogs
"Tim" <tnorton@xxxxxxxxxxx> wrote in message
news:1156631884.613836.301330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have the following function that returns the path of where the
program was run from.
However I cant seem to return the butter as a CHAR. The code works if I
use it in a procedure but not where I need to return the variable CHAR
buffer.
char CAutoRunDlg::GetProgramPath(void)
{
char buffer[_MAX_PATH]; //declares maimum path
//opens window maximized
//_getcwd(,)gets the current working directory
// #include <direct.h> //needed for current working directory
/* Get the current working directory: */
if( _getcwd( buffer, _MAX_PATH ) == NULL )
perror( "_getcwd error" );
else
printf( "%s\n", buffer );
return buffer;
}
.
- Follow-Ups:
- Re: Returning a CHAR[] from a function
- From: David Webber
- Re: Returning a CHAR[] from a function
- References:
- Returning a CHAR[] from a function
- From: Tim
- Returning a CHAR[] from a function
- Prev by Date: Re: tracking down error in MFC42.dll
- Next by Date: Re: Should Globally Needed Objects be Members in Main Frame, Application, or be Global?
- Previous by thread: Re: Returning a CHAR[] from a function
- Next by thread: Re: Returning a CHAR[] from a function
- Index(es):
Loading