title: fclose, fopen and fwrite issues with writing multiple files
body: <p>I have a program that records data from a serial port. Every so often, I want to split up files such that the data logs don't become very large. The problem is, after I recreate the FILE* and try to write into it, the program crashes. No compiler errors/warnings before hand also...</p>
  
  <p>The program does create one log for the first time interval, but once it's time to create a new data log, it crashes at the fwrite.</p>
  
  <p>First off, initializations/declarations.</p>
  
  <pre><code>char * DATA_DIR = "C:\DATA";
  sprintf(path,"%s%s%s",DATA_DIR,curtime,".log"); //curtime is just the current time in a string
  FILE * DATA_LOG = fopen(path, "wb+");   
  </code></pre>
  
  <p>And later on in a while loop</p>
  
  <pre><code>if(((CURRENT_TIME-PREVIOUS_TIME) &gt; (SEC_IN_MINUTE * MINUTE_CHUNKS) ) &amp;&amp; (MINUTE_CHUNKS != 0) &amp;&amp; FIRST_TIME == 0) //all this does is just checks if its time to make a new file
  {
      fclose(DATA_LOG); //end the current fileread
  
      char * path; 
      char curtime[16];
  
      //gets the current time and saves it to a file name
      sprintf(curtime , "%s" , currentDateTime());
      sprintf(path,"%s%s%s",DATA_DIR,curtime,".log");
  
      DATA_LOG = fopen(path, "wb+"); //open the new file
  
      //just some logic (not relevant to problem)
      PREVIOUS_TIME = CURRENT_TIME; 
      newDirFlag = 1;
  }
  fwrite(cdata , sizeof(char) , numChars , DATA_LOG); //crashes here. cdata, sizeof, and numChars don't change values
  </code></pre>
  
  <p>Any ideas why is this happening? I'm stumped.</p>