title: deleting a record using arrays
body: <p>I am a complete beginner in c++, so bear with me. I have been asked to write a program and one of the functions is to delete a record from a file and place it in another file using arrays (with an unknown size hence the counter). I have tried many different methods but to no avail. Now I got the <code>abort()</code> error and I really don't know what to do or fix. Your help is greatly needed.</p>
  
  <pre><code>void DeletePatient ()
  {
      ifstream infile;
      infile.open ("patients.txt");
  
      ofstream outfile;
      outfile.open ("deletedpatients.txt");
  
      int i=0, flag=0, counter=0, deleteID, deletedindex;
  
      //Read contents into array
  
      while(!infile.eof())
      {
          infile&gt;&gt;IDnumber[i]&gt;&gt; FirstName [i] &gt;&gt; LastName [i] &gt;&gt; PhoneNumber [i] &gt;&gt; Nationality [i];
          i++;
          counter++;
      }
  
      if ( !infile )
          cout &lt;&lt; "Error opening file\n";
      else  
      {
          cout&lt;&lt;"Enter ID number of patient to be deleted\n";
          cin &gt;&gt; deleteID;
  
          for(i=0;i&lt;counter;i++)
          {
              if(deleteID==IDnumber[i])
              {
  
                  infile &gt;&gt; IDnumber [i] &gt;&gt; FirstName [i] &gt;&gt; LastName [i] &gt;&gt; PhoneNumber [i] &gt;&gt; Nationality [i];
  
                  outfile &lt;&lt; IDnumber [i] &lt;&lt;" "&lt;&lt; FirstName [i]&lt;&lt;" " &lt;&lt; LastName [i]&lt;&lt;" " &lt;&lt; PhoneNumber [i]&lt;&lt;" " &lt;&lt; Nationality [i];
  
                  flag++;
  
                  for(deletedindex=i; i&lt;counter; deletedindex++)
                  {
                      IDnumber[deletedindex]=IDnumber[deletedindex+1];
                      FirstName[deletedindex]=FirstName[deletedindex+1];
                      LastName[deletedindex]=LastName[deletedindex+1];
                      PhoneNumber[deletedindex]=PhoneNumber[deletedindex+1];
                      Nationality[deletedindex]=Nationality[deletedindex+1];
                  }
  
              }
          }
  
          infile.close();
  
          if(flag==0)
              cout&lt;&lt;"User does not exsist\n";
          else
          {
              ofstream updatefile;
              updatefile.open("patients.txt");
  
              for ( i=0 ; i &lt; counter; i++ ) //update file
              {
  
                  updatefile &lt;&lt; IDnumber [i] &lt;&lt;" "&lt;&lt; FirstName [i]&lt;&lt;" " &lt;&lt; LastName [i]&lt;&lt;" " &lt;&lt; PhoneNumber [i]&lt;&lt;" " &lt;&lt; Nationality [i];
              }   
              cout &lt;&lt; "Patient is deleted" &lt;&lt; endl;
              updatefile.close();
          }
      }
  
      outfile.close ();
  }
  </code></pre>