I have this code. I want to update the writes immediately to log file before closing the file (because my program might get hang and I have to exit it by ctrl+c so fclose would never be called). The code is:
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main()
5 {
6 FILE* fp = fopen("test.log","wb");
7 if (fp == NULL)
8 {
9 printf("file not found\n");
10 exit(1);
11 }
12
13 fprintf(fp, "today is %d day\n",420);
14 fflush(fp);
15 getchar();
16 fclose(fp);
17
18 return 0;
19 }
but even though I force it to halt at line 15 so that I can view the log file from another console, I do not see any output written when opening the file. I am not sure why it is not working as expected.
Need some help here.
Thanks.