title: Create a file if one doesn't exist - C
body: <p>I want my program to open a file if it exists, or else create the file. I'm trying the following code but I'm getting a debug assertion at freopen.c. Would I be better off using fclose and then fopen immediately afterward?</p>
  
  <pre><code>FILE *fptr;
      fptr = fopen("scores.dat", "rb+");
      if(fptr == NULL) //if file does not exist, create it
      {
          freopen("scores.dat", "wb", fptr);
      } 
  </code></pre>