So I'm working on an assignment for my class in which I have to read in data from a file and create a doubly linked list with it. I have all the difficult stuff done, now I'm just running into the problem where my program throws a bunch of random characters and kills itself on the last line.
Here is the function that is reading in the data and inserting it into my link list. My professor wrote this, so to be frank, I don't understand it very well.
void PropogateTheList(ifstream & f, LinkList & ML)
{
  static PieCake_struct * record;
  record= new PieCake_struct;
  f>>record->id>>record->lname>>record->fname>>record->mi>>record->sex>>record->pORc;
  while(!f.eof())
  {
    ML.Insert(record);
    record = new PieCake_struct;
    f>>record->id>>record->lname>>record->fname>>record->mi>>record->sex>>record->pORc;
  }
}
Here is the data that is being propagated:
1   Abay         Harege N O C
2   Adcock       Leand R F P
3   Anderson     Logan B M P
5   Bautista     Gloria A F P
10  Beckett      Dallas B F C
12  Ambrose      Bridget C F C
13  Beekmann     Marvin D M P
14  Bacaner      Tate D M C
16  Bis          Daniel F M P
18  Dale         Kaleisa G F C
19  DaCosta      Ricardo H M P
23  Adeyemo      Oluwanifemi I M C
24  Berger       Chelsea J F C
38  Daniels      Jazmyn K F P
39  Davis        Takaiyh L F C
40  DeJesus      Gabriel M M P
51  Castro       Floriana N F P
52  Chen         Justin O M C
53  Clouden      Ariel P F P
54  Conroy       Cameron Q M C
61  Contreras    Dominic R M P
62  Cooley       Kyle S M C
63  Creighton    Cara T F P
64  Cullen       William U M C
66  Blakey       Casey V M  C
67  Barbosa      Anilda W F P
83  Brecher      Benjamin X M P
84  Boulos       Alexandre Y F C
85  Barrios      Joshua Z M C
85  Bonaventura  Nash A M P
86  Bohnsack     David B M C
87  Blume        Jeffrey C M P
90  Burgman      Megan D F C
91  Bursic       Gregory E M P
92  Calvo        Sajoni F F C
93  Cannan       Austin G M  P
94  Carballo     Nicholas H M C
99  AlbarDiaz    Matias I F P
Currently, I sort the data alphabetically based off the last name, so on about the 5th line, when it tries to print out number 99 (AlabraDiaz) it dies. If I sort the list another way, the program always messes up with whatever the last line of data is. Any help would be great!
UPDATE:
So I've tried implementing an if(!.eof()) before inserting but it unfortunately doesn't do anything. I deleted the last of data, thus making the person Carballo. This is what my function prints out:
****** The CheeseCake Survey ****** 
Id      Last Name       First Name      MI      Sex     Pie/Cake
--      --------        ---------       --      ---     --------
2       Adcock
23      Adeyemo
12      Ambrose
3       Anderson
14      Bacaner
67      Barbosa
85      Barrios
5       Bautista
10      Beckett
13      Beekmann
24      Berger
16      Bis
66      Blakey
87      Blume
86      Bohnsack
85      Bonaventura
84      Boulos
83      Brecher
90      Burgman
91      Bursic
92      Calvo
93      Cannan
0       Carballo????NicholasA8?zL`8?zL`A8?zL`8?zL`??
 
    