Thread: Common Dialog Boxes problem

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Common Dialog Boxes problem

    Try this code and try to select "save as txt" from the file menu. Every time you try this the program crashes. Why is this?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You fail to init the file name before adding the .txt to the end of it.

    Also make sure you check the length of the string before adding to it.

    Try
    sprintf(filename,"Roster for %s.txt",date);
    (but ensure that there are no punctuation characters)

    Something like
    Code:
    char     *pDate=NULL,*pNewDate=NULL,sNewDate[64];
    pDate=date;//set the pointers to the begining of the strings
    pNewDate=sNewDate;
    
    while(*pDate != '\0')
    {
        while(ispunct(*pDate))	*pDate++;
        //while(isspace(*pDate))	*pDate++;
        *pNewDate++=*pDate++;
    }
    pNewDate++='\0';//set terminator
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Make sure the path and filename variables in your Ouput function are initialized:

    Change:
    Code:
    char path[MAX_PATH];
    char filename[MAX_PATH];
    To
    Code:
    char path[MAX_PATH] = "";
    char filename[MAX_PATH] = "";
    I think this will solve your problem.

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Thanks for replying, the problem was that I hadn't initialised the two arrays (path and filename), but I still have a problem: It still doesn't actually save the file. Is there something I'm doing wrong with the file output?

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    That's because the path variable automatically includes the filename. If you add the filename to the path your path will look like this:
    Code:
    C:\Temp\Roster\test.txt\test.txt.txt
    Remove the next 3 lines and it will work:
    Code:
    strcat(filename, ".txt");
    strcat(path, "\\");
    strcat(path, filename);
    B.t.w. Are you using Visual Studio? If so, why don't you place some beakpoints and debug the stuff?

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I didn't actual compile the code. But I think I see the problem. Doesn't GetSaveFileName() give you a full path? If so you are appending the full path to the path, then adding a second extension to it. Double check that.

  7. #7
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Ah, thankyou that worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Two quick questions about open file dialog boxes
    By PJYelton in forum Windows Programming
    Replies: 5
    Last Post: 04-05-2005, 08:49 AM
  2. Buttons In Dialog Boxes
    By ElWhapo in forum Windows Programming
    Replies: 2
    Last Post: 02-10-2005, 06:46 PM
  3. problem with the open dialog box
    By stallion in forum Windows Programming
    Replies: 13
    Last Post: 02-19-2003, 08:28 AM
  4. stupid problem in Dialog based Apps by MFC
    By AsAdi in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2003, 01:47 PM