FILE* problem
-
Hi, I'm now using the File* to save the data into text file. But i notice that if the file i want to save is in open mode, then the program will crash. Any way to prevent it? Below is snap of my code.. In *.h file
FILE *handle;
in *.cpp file
fopen_s(&handle,cPathName,"wt");
fprintf(handle,"<?xml version=\"1.0\"?>\n") // crash at here -
Hi, I'm now using the File* to save the data into text file. But i notice that if the file i want to save is in open mode, then the program will crash. Any way to prevent it? Below is snap of my code.. In *.h file
FILE *handle;
in *.cpp file
fopen_s(&handle,cPathName,"wt");
fprintf(handle,"<?xml version=\"1.0\"?>\n") // crash at herefopen_s
has a return value that you must check for errors. This way you will write only if the open operation was successful, thereby avoiding the crash.«_Superman_»
I love work. It gives me something to do between weekends. -
Hi, I'm now using the File* to save the data into text file. But i notice that if the file i want to save is in open mode, then the program will crash. Any way to prevent it? Below is snap of my code.. In *.h file
FILE *handle;
in *.cpp file
fopen_s(&handle,cPathName,"wt");
fprintf(handle,"<?xml version=\"1.0\"?>\n") // crash at here -
Hi, I'm now using the File* to save the data into text file. But i notice that if the file i want to save is in open mode, then the program will crash. Any way to prevent it? Below is snap of my code.. In *.h file
FILE *handle;
in *.cpp file
fopen_s(&handle,cPathName,"wt");
fprintf(handle,"<?xml version=\"1.0\"?>\n") // crash at herePlease check if the "handle" is NULL.
fopen_s(&handle,cPathName,"wt");
if (handle != NULL)
{
fprintf(handle,"<?xml version=\"1.0\"?>\n")
}Working is a happy thing! Enjoy free partition manager!