title: Removing and renaming files with C error
body: <p>So i'm trying updating data from original file to a new temporary file, then i remove the original file and rename the temp file with the name of the original one like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;time.h&gt;
  
  int main(){
   FILE * fptr = NULL;
   FILE * temp;
  
      fptr = fopen("Original.txt", "rw+");
      temp = fopen("temp.txt", "w");
  
      if(fptr==NULL)//Check if file was opened successfully
      {
          printf("File could not be opened");
      }
  
  
      //cicle of me adding data to temp file
  
      fclose(fptr);
      fclose(temp);
  
      remove("Original.txt");
      rename("temp.txt","Original.txt");
  
      return 0;
      }
  </code></pre>
  
  <p>it works the first time, but when i execute again the Original.txt ends up blank. What can be causing that?</p>
  
  <p>I've tried changing temp = fopen("temp.txt", "w"); to temp = fopen("temp.txt", "ab+"); but the info of Original.txt ends up with no spaces or new lines between (all together). And same with "wb"</p>
  
  <p>"rb" the Original.txt file disappears.</p>
  
  <p>if necessary ill add the entire code, althought i dont think its revelant</p>