Common Dialog Boxes problem

This is a discussion on Common Dialog Boxes problem within the Windows Programming forums, part of the Platform Specific Boards category; Try this code and try to select "save as txt" from the file menu. Every time you try this the ...

  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?
    Attached Files Attached Files

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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, 05:46 PM
  3. problem with the open dialog box
    By stallion in forum Windows Programming
    Replies: 13
    Last Post: 02-19-2003, 07:28 AM
  4. stupid problem in Dialog based Apps by MFC
    By AsAdi in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2003, 12:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21