title: Program hangs if both written to and read from file in same execution
body: <p>I would expect the following code to write the number 42 to a binary file and then read and print out the exact value. And it does that but then it will not exit, just stall as it would when waiting for user input. Here is code that does what I explained:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char argv[]){
  
      char *filename = "test.db";
      int *my_int = calloc(1, sizeof(int));
      *my_int = 42;
  
      // First we open file to write to it
      FILE *file = fopen(filename, "w");
      fwrite(my_int, sizeof(int), 1, file);
      fflush(file);
      free(file);
  
      // Then we want to read from it
      *my_int = -1;
      file = fopen(filename, "r");
      fread(my_int, sizeof(int), 1, file);
      free(file);
  
      printf("Read back %d\n", *my_int);
  
      return 0;
  }
  </code></pre>
  
  <p>I know that I can simply open it with the <code>w+</code> flag but I am just curious to figure out why it just stalls..</p>