OPENFILENAME / Replacing Char Array

Hi Guys,

I'm trying to grab a file path through windows' OPENFILENAME
then load it with fopen.
One problem: Windows returns the path as 'C:\Users\Dylan\Documents\Coding Projects\My Platformer\maps\1.map',
but fopen reads 'C:/Users/Dylan/Documents/Coding Projects/My Platformer/maps/1.map'. So I tried to replace all of the '\' with '/' using this method: (I know there is std::replace)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    

    //from http://www.winprog.org/tutorial/app_two.html

    OPENFILENAME ofn;
    char szFileName[MAX_PATH] = "";

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFilter = "Map Files (*.map)\0*.map\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

    using std::replace;

    if(GetOpenFileName(&ofn))
    {
                 //szFilename length is 260
        for(int i = 0; i < 260; i++)
        {
            switch(szFileName[i])
            {

                 case '\': szFileName[i] = '/';   break;
            }
        }


    }

    printf(szFileName); 


which gives me the error: missing terminating ' character. How can I get around this?

Thanks in Advance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
OPENFILENAME ofn;
    char szFileName[MAX_PATH];
szFileName[0] = '\0';

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFilter = "Map Files (*.map)\0*.map\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

    //using std::replace;

    if(GetOpenFileName(&ofn))
    {
        std::string fileName = ofn.lpstrFile;
        std::replace(fileName.begin(), fileName.end(), '\', '/');
    } 
Thanks for the reply savavampir, though I'm still getting the same error: missing terminating ' character

Here's a link to a screenshot i took:
http://i1224.photobucket.com/albums/ee368/D_Cipher404/C.png

Could it have anything to do with my IDE Code::Blocks?
You need two \ inside the first character because \ is the escape character:

std::replace(fileName.begin(), fileName.end(), '\\', '/');
Thanks everyone - It works now.
Topic archived. No new replies allowed.