store text to nodes

so in this program i have two structs
1
2
3
4
5
6
7
8
9
10
11
struct node{

	string data;
	node* next;
	node* prev;
};

struct list{
	node* head;
	node* tail;
};


one is just nodes for a doubly linked list and the other one stores head and tail pointer.

I am creating a function that creates the list and returns the list, (which will be a head pointer and a tail pointer).

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
list* read(string fn){
	
	ifstream file(fn);	
	node* no;
	string temp;
	lista* bn;
	bn = new list;	
		
	if (file.is_open()){

		if (bn->head == NULL) //if list is empty
		{
			no = new node;
			file >> no->data;
			no->prev = NULL;
			no->next = NULL;
			bn->head = no;
			bn->tail = no;

		}

		while (file.is_open()){

			no = new node;
			file >> no->data;
			
			no->next = NULL;
			no->prev = bn->tail;
			bn->tail->next = no; //here is where i get the error
			bn->tail = NULL;

			if (file.eof()){file.close();}
		}
		
	}
	else { cout << "Unable to open file"; }

	
	return bn;
	
}


why is this not working?
Explain line 30.
this is what i have now:

1
2
3
4
5
6
7
8
9

 no = new node;              // new node created
 file >> no->data;          //data passed to it
 no->next = NULL;        //there is nothing in front of the node 
 no->prev = tailz;        // Behind the new node will be the tail
 tailz->next = no;       // in front of the tail will be the new node
 tailz = no;                // now the new node is the tail 
 tailz->next = NULL; // there is nothing in front of the tail
Topic archived. No new replies allowed.