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?
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?
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
Make sure the path and filename variables in your Ouput function are initialized:
Change:
ToCode:char path[MAX_PATH]; char filename[MAX_PATH];
I think this will solve your problem.Code:char path[MAX_PATH] = ""; char filename[MAX_PATH] = "";
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?
That's because the path variable automatically includes the filename. If you add the filename to the path your path will look like this:
Remove the next 3 lines and it will work:Code:C:\Temp\Roster\test.txt\test.txt.txt
B.t.w. Are you using Visual Studio? If so, why don't you place some beakpoints and debug the stuff?Code:strcat(filename, ".txt"); strcat(path, "\\"); strcat(path, filename);
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.