use file path from OpenFileDialog

I need some help. I'm using an OpenFileDialog to get the the path of files.
I have the following lines:

String^ filenname = System::IO::Path::GetFileName(openFileDialog1->FileName);
String^ path = System::IO::Path::GetDirectoryName(openFileDialog1->FileName);
MessageBox::Show(path=path+"\\"+filenname, "Directory");

The path is perfect but I need the path in a char* so I did this:

char *filname=new char[path->Length];

for( i=0;i<path->Length;i++)
{
filname[i]=Convert::ToChar(path[i]);
}

However I get that the file doesn't exist(!)

the filname value looks like this:
D:\4.jpgýýýý««««««««þîþ (!)

the path value:
D:\4.jpg

And the path->Length=8 ..so filname is 8 characters long:-s

If I write: char *filename=(char*)"D:\4.jpg" it works!:-s

What should I do?
You didn't null terminate the string.
1
2
3
4
5
for( i=0;i<path->Length;i++)
{
    filname[i]=Convert::ToChar(path[i]);
}
filename[i] = 0;   // gotta do this! 

Topic archived. No new replies allowed.