Archived

This topic is now archived and is closed to further replies.

Open file

This topic is 5650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have this piece of code for a commondialog: OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName } how do i use the szFilename in the fopen function to open the file i select??

Share this post


Link to post
Share on other sites
Do you mean:


FILE* fp = fopen(szFilename,"rb"); // open for reading

if(fp == NULL)
{
// error opening file
}

fread(mybuffer,512,sizeof(char),fp);


?

You might want to also look into the iostream if using C++.

Share this post


Link to post
Share on other sites