still struggling with the linked list

My assignment is due tonight and I can not get this code to write the text from a text file into struct nodes. It writes the first line but doesn't add after that. Please help me fix this code to work with multiple lines of text in a text file.

I know that there is stuff that doesn't belong in here but I need to get it working.

Main:
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
	#include <string>
	#include <iostream>
	#include <fstream>
	#include <cstdlib>
	#include <sstream>
	#include "Assignment4.h"
	
	//GetFileName
 string getFileName()
 {
 string fileName;	
 cout << "Enter Name of file to open INCLUDING extension ::" << endl;
 cin >> fileName;
 //================test to make sure the fileName name has a txt extension
 string ext="";
for(int i = fileName.length()-1;i>fileName.length()-5;i--)
{
    ext += fileName[i];
}//end for

if(ext != "txt.")
 { 
    cout<<"File name does not contain the proper extension, Please Enter Name of file to open INCLUDING extension :: " <<endl;
    cin >> fileName;
 }//end if
 return fileName;
 }//end getFileName
 
 //******************************************
 void print_list(Personnel *in_root)
 //=======================================
 // PRINT LIST CONTENTS
 //=======================================
 {
 	Personnel *next_ptr;
 	next_ptr = in_root;
 	
 	if(next_ptr == NULL)
 	{
 		cout << "EMPTY LIST: No nodes to print...." << endl;
	}//end if
	else
	{
		while(next_ptr != NULL)
		{
			cout << next_ptr -> firstName << endl;
			cout << next_ptr -> lastName << endl;
			cout << next_ptr -> jobTitle << endl;
			cout << next_ptr -> empStatus << endl;
			cout << next_ptr -> wage << endl;
			next_ptr = next_ptr -> next;
		}//end while
	}//end else
	system("pause");
 }//end print_list
 
 //=====================Add node by manual input.
 Personnel *add_node(Personnel *in_root)
 //=========================================
 // ADD A NEW NODE
 //=========================================
 {
 	Personnel *next_ptr = NULL;
 	Personnel *prev_ptr = NULL;
 	
 	if(in_root == NULL)
 	{
 		// list is empty
 		if((in_root = new Personnel) != NULL)
 		{
 			next_ptr = in_root;
 			
 			cout << "First Name: ";
 			cin >> next_ptr -> firstName;
 			cout << "Last Name: ";
 			cin >> next_ptr -> lastName;
 			cout << "Job Title: ";
 			cin >> next_ptr -> jobTitle;
 			cout << "Employments Status <F>ull or <P>art time: ";
 			cin >> next_ptr -> empStatus;
 			cout << "Wage: ";
 			cin >> next_ptr -> wage;
 			 			
 			next_ptr -> next = NULL;
 		}//end if
 		else
 		{
 			cout << "ERROR: Unable to allocate memory." << endl;
 			return NULL;
		}//end else
 		return next_ptr;
	}//end if
 	else
 	{
 		//list has members
 		next_ptr = in_root;
 		while(next_ptr -> next != NULL)
 		{
 			next_ptr = next_ptr -> next;
 	    }//end while
 	    prev_ptr = next_ptr;
 	    if((next_ptr = new Personnel) != NULL)
 	    {
 	    	prev_ptr -> next = next_ptr;
 			cout << "First Name: ";
 			cin >> next_ptr -> firstName;
 			cout << "Last Name: ";
 			cin >> next_ptr -> lastName;
 			cout << "Job Title: ";
 			cin >> next_ptr -> jobTitle;
 			cout << "Employments Status <F>ull or <P>art time: ";
 			cin >> next_ptr -> empStatus;
 			cout << "Wage: ";
 			cin >> next_ptr -> wage;
 			
 			next_ptr -> next = NULL;
		}//end if
		else
		{
			cout << "ERROR: Unable to allocate memory." << endl;
		}//end else
		return in_root;
 	}//end else
 }//end Personnel
 
 //=================add node from text file
 Personnel *insertFromFile (Personnel *in_root)
 {
	Personnel *next_ptr = NULL;
	Personnel *prev_ptr = NULL;
	string firstName, lastName, jobTitle, fileName;
	char empStatus;
	double wage;
	ifstream file;
	fileName = getFileName();
	file.open(fileName.c_str());
	
 	if(file.is_open())
    {
 
   while(file) 
 //while (file >> firstName >> lastName >> jobTitle >> empStatus >> wage)
     {

 	if(in_root == NULL)
 	{
 		// list is empty
 		if((in_root = new Personnel) != NULL)
 		{
 		
 			next_ptr = in_root;
 			file >> next_ptr -> firstName;
			file >> next_ptr -> lastName;
			file >> next_ptr -> jobTitle;
			file >> next_ptr -> empStatus;
			file >> next_ptr -> wage;

 			next_ptr -> next = NULL;
 		}//end if
	 		else
	 		{
	 			cout << "ERROR: Unable to allocate memory." << endl;
	 			return NULL;
			}//end else
 		return next_ptr;
	}//end if
 	else
 	{
 		//list has members
 		next_ptr = in_root;
 		while(next_ptr -> next != NULL)
 		{
 			next_ptr = next_ptr -> next;
 	    }//end while
 	    prev_ptr = next_ptr;
 	    if((next_ptr = new Personnel) != NULL)
 	    {
 	    	prev_ptr -> next = next_ptr;
         file >> next_ptr -> firstName;
 		 file >> next_ptr -> firstName;
		 file >> next_ptr -> lastName;
         file >> next_ptr -> jobTitle;
         file >> next_ptr -> empStatus;
         file >> next_ptr -> wage;	
 		
		}//end if
		else
		{
			cout << "ERROR: Unable to allocate memory." << endl;
		}//end else
		return in_root;
 	}//end else
     }//end while
    exit(EXIT_FAILURE);
       cout << "File did not open." << endl;
       
      // file.close();
    }// end if
   // file.close();
	}//end insertFromFile

// void insertAtHead (PersonnelPtr& head, string firstName, string lastName, string jobTitle, char empStatus, double wage)
// {
// //PersonnelPtr tempPtr = new Personnel;
// PersonnelPtr next_ptr = new Personnel;
// //Personnel *next_ptr;
// //next_ptr = in_root;
// 
// next_ptr->firstName = firstName;
// next_ptr->lastName = lastName;
// next_ptr->jobTitle = jobTitle;
// next_ptr->empStatus = empStatus;
// next_ptr->wage = wage;
// 
// next_ptr->next = head;
// head = next_ptr;
//}//end void
 //=====================getUserInfo=====
 void getUserInfo()
 {
 	string *firstName, *lastName, *jobTitle;
 	char *empStatus;
 	double *wage;
 	cout << "Enter FIRST name of associate :" << endl;
 	cin >> *firstName;
 	cout << "Enter LAST name of associate :" << endl;
 	cin >> *lastName;
 	cout << "Enter job title of associate :" << endl;
 	cin >> *jobTitle;
 	
 	    while (*empStatus != 'P' && *empStatus != 'p' && *empStatus != 'F' && *empStatus != 'f')
 	    {
 	    	cout << "Is associate <F>ull OR <P>art time ?" << endl;
 	cin >> *empStatus;
		 }//end while
    cout << "Enter hourly wage :" << endl;
    cin >> *wage;
 }//end getUserInput
 
 void GetTextFromFile(ifstream& file)
 {
 string firstName, lastName, jobTitle, fileName;
 char empStatus;
 double wage;
 
 if(file.is_open())
    {
    	cout << "File is open" << endl;
    }
 
 PersonnelPtr head = new Personnel;
 	
  while (file >> firstName >> lastName >> jobTitle >> empStatus >> wage)
  cout << firstName << endl;
		  {
		    insertAtHead (head, firstName, lastName, jobTitle, empStatus, wage);
	      }//end while	
 }//end GetTextFromFile
  
 //============menu======	
 void menu()
 {
    ifstream file;
    string fileName;
 	string searchValue;
	Personnel *head = NULL;
	char choice;
 	bool quit = false;
	while (!quit)
      {
 	cout << "*****MENU*****" << endl;
 	cout << "1. Add items from Text File" << endl;
 	cout << "2. Manually Add Item" << endl;
 	cout << "3. Print ALL associates" << endl;
 	cout << "4. Search and Print" << endl;
 	cout << "5. EXIT" << endl;
 	 cout << "Enter a menu choice: " << endl;
        cin >> choice;
        cout << endl;
 	 	
 		switch (choice)
 		{
 			case '1': head = insertFromFile(head);
			 break;
			 
			case '2': head = add_node(head);
			 break;
			 
			case '3': print_list(head);
			 break;
			 
			case '4': cout << "Enter LAST name to search for::" << endl;
			          cin >> searchValue;
			          //head = SearchRecursive(in_root, searchValue);
			//cout << "Function to search for and print an associate to screen" << endl;
			 break;
			 
			case '5': cout << "EXIT" << endl; 
			 quit = true;
			 break;  
		}//end switch
	}//end while
 }//end menu
 
 int main()
 { 
 //-----------variables
	menu();
	system("pause");
	return 0;
 }//end main 


Header:
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
using namespace std;
 
 struct Personnel {

 string firstName;
 string lastName;
 string jobTitle;
 char empStatus;
 double wage;
 Personnel *next;

 bool read (istream& file);
 bool print (ostream& os);
 	
 };// end struct
 
 typedef Personnel* PersonnelPtr;
 Personnel *add_node (Personnel *in_root);
 void print_list (Personnel *in_root);
 string fileOpen();
 //Personnel *insertFromFile (Personnel *in_root);
 void menu();
 void SearchRecursive(Personnel *in_root);
 void insertAtHead (PersonnelPtr&, string, string, string, char, double);
 void GetTextFromFile(ifstream&);
 bool read (istream&);
 bool print (ostream&);

Topic archived. No new replies allowed.