Fail to write to file when I force quit
<p>I have a program that looks like this. I need to consistently write something into a text file but I cannot predetermine when the program is going to end. So I force quit the program.</p>

<pre><code>FILE *f = fopen("text.txt", "w");
while (1) {
    fprintf(f, "something");
    sleep(1000);
}
</code></pre>

<p>The problem is that the text file would be empty. Can anyone give me some suggestions?
I am using XCode to do the job.</p>
