I created a method to get a file in the current directory:
When I request a file the method returns a string, which can be shown by a messagebox, but when I try to write it to a file I get:Code:LPSTR CApplication::GetFile(LPSTR File) { char Path[1000]; GetModuleFileName(m_hInst,Path,1000); for(UINT x=(UINT)strlen(Path);x>0;x--) if(Path[x]=='\\') break; Path[x+1]='\0'; strcat(Path,File); LPSTR ReturnPath=Path; return ReturnPath; }
what am I doing wrong?Code:08 11 F4 77 1E (hex)
thanks in advance,
borre mosch



LinkBack URL
About LinkBacks



You're returning a pointer to a local array. When the function returns, the memory for Path is released so you can no longer reference it. Maybe something like this would fix that particular problem, but your function is still suspect: