I am writing the log file in my c application, the method for writing the file is
fopen_s(&fMainFile, "c:\\LOG\\Filter.txt", "a");
fprintf(fMainFile, "SomeText");
fclose(fMainFile);
I open the handle, after writing I closed it, but this writing crash my application after a while, can any one sort out this problem, that how much dangerous to open and close the handle again and again, or proposed any other approach for writhing the file.
How is fMainFile defined? I suspect that you shoud have:
Pass a reference to the fprintf/fclose functions as you did with fopen_s!
EDIT: this answer is not valid, since fopen_s takes a FILE** parameter as stated below in comments.
EDIT2: As i said in comments you should do buffered writing (either with your own buffer or using setvbuf() functions for your file). Also, do not reopen/close the file every time, but leave it open and close it only when you really need to (input is finished). use fflush() to force writing to disk (instead of fclose()).