substring reading from a file

im trying to read information from a file, when i run my program all im getting is random garbage, my professor told me to use substrings, can anyone help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

#include "qhead.h"



const int MaxNameLen = 20;



struct WaitingList {

 char        ownerName[MaxNameLen];
 char        petName[MaxNameLen];
 int         emeCode;
};


int main () 
 {
  Queue waitingList;
  string filename;
 ifstream in;
in.open ("f:\\patient.txt");
 if (!in) {
  cerr << "Error: cannot open the file " << filename << endl;
   system("pause");
  exit (2);
 }
 char type;
 string line;
 while (in >> type)
 {
  if (type == 'H')
  {
  WaitingList* ptrstudent = (WaitingList*) waitingList.Dequeue ();
   if (ptrstudent) {
    cout << "Treated: " << ptrstudent->ownerName << ptrstudent->petName  << endl;
    delete ptrstudent;
	  
   }
  }
  else  if (type == 'A')
  {

   getline (in, line);
    WaitingList* ptrnew = new (std::nothrow) WaitingList;
	 if (!ptrnew) {
		 cerr << "Error - out of memory\n";
		 system("pause");
		 exit (1);
		 }

 // break line into substrings
	 
      
   waitingList.Enqueue (ptrnew);
   cout << "Added patient: " << ptrnew->ownerName << ptrnew->petName << endl;
  }
  else 
   cerr << "Error: invalid transaction code encountered.\n"
        << "It was: " << type << endl;

 }
 in.close ();
 system("pause");
 return 0;
}
 



it should look like this
Added: Samuel Spade Fido
Added: John Jones Rover
Added: Betsy Ann Smithville Jenny
Treated: Samuel Spade Fido
Treated: John Jones Rover
Added: Lou Ann deVille Kitty
Treated: Lou Ann deVille Kitty
Added: Tom Smythe Fifi
Added: Marie Longfellow Jack
Treated: Marie Longfellow Jack
Treated: Betsy Ann Smithville Jenny
Treated: Tom Smythe Fifi

Topic archived. No new replies allowed.