Re: Returning a CHAR[] from a function



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;
}



.


Loading