Possible Duplicate:
Is it a good idea to return “ const char * ” from a function?
how to return char array in c++?
What is wrong with this return? I'm trying to return the current path using the following function but it doesn't seems to be correct:
Please Not: I need an char return not string.
char* getINIfile(void)
{
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
string path = string( buffer ).substr( 0, pos) + "\\setup.ini";
char *ini_local= (char*)path.c_str();
printf(ini_local); // so far output OK!
return ini_local;
}
main
{
printf(getINIfile()); // output Not OK!
char mybuffer[200];
GetPrivateProfileStringA( "files","DLL","0", mybuffer,200, getINIfile());
printf(mybuffer);
}