Struggling with pointers

I am trying to move a player down a linked list after they've made their choice of going left or right after storing the data in the .data portion(as dictated by a called txt file containing these values)

I've so far figured out how to store the data seperatly in a stack, but then cannot for the life of me how to then move the player on to the next item

Heres what I have so far(not started on the right choice yet, as its literally going to be the opposite of left):

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
  #include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;


class node
{
	public:
		int left;
		char data;
		int right;
};

node *start_ptr = NULL;
node *current_ptr;


void wordmaze(node maze[10][10])
{
	int row, col;//file>>array>>.left/right/data
	ifstream wordmaze;
		wordmaze.open("wordmaze.txt");
	for(row=0;row<10;row++)
		for(col=0;col<10;col++)
	{
		wordmaze>>maze[row][col].left;
		wordmaze>>maze[row][col].data;
		wordmaze>>maze[row][col].right;
	}
}

/*void letterlist(char stack[20],int &tos)
{
	int row, col;
	node maze[10][10];
	wordmaze(maze);
 if (tos==-1)
	 cout<<"Stack overflow Error"<<endl;
 else 
	{	
		tos--;
		cin>>maze[row][col].data;
		cin>>stack[tos];
	}

}*/

class stack
{
	char stacklist[20];
	int tos, &tos;
public:
	stack(){tos = 0;}
	void push(char ch)
	{
		if(tos==20)
		{
			cout<<"list is full"<<endl;
			return;
		}
		stacklist[tos] = ch;
		tos++;
	}
	char pop()
	{
		if (tos==0)
		{
			cout<<"List is Empty"<<endl;
			return 0;
		}
		tos--;
			return stacklist[tos];
	}
};

void play()
{
	node maze[10][10];
	wordmaze(maze);
	int row, col, moves;
	char playerchoice, Left, Right;
	stack stackobject1;
	char stacklist[20];
	int tos, &tos;

	cout<<"Please choose a direction: Left or Right:"<<endl;
		cin>>playerchoice;
	if(playerchoice==Left&&moves<20)
	{
		cout<<maze[row][col].left;
		moves++;
		cout<<moves;		
		maze[row][col].data=stacklist[tos];
		tos--;
		cout<<stacklist;

		return;		
		//move player to row/col on left
	}
	if(playerchoice==Right&&moves<20)
	{
		cout<<maze[row][col].right;
		moves++;
		cout<<moves;
		//pass maze.data to stack
		//move player to row,col on right
	}
}

void wordmazeshow()
{
	ifstream wordmaze("wordmaze.txt");
	int left;
	string letter;
	int right;

	while(wordmaze>>left>>letter>>right)
	{
		cout<<left<<"   "<<letter<<"   "<<right<<endl;
	}

}

void main()
{
	char option;
	char stack[20];
	int tos=-1;

  do
  {
	 cout<<endl<<endl<<endl;
	 cout<<"Menu"<<endl<<endl;
	 cout<<"1.  Play Game"<<endl;
	 cout<<"2.  Show Maze"<<endl;
	 cout<<"Q.  Quit system"<<endl<<endl;
	 cout<<"Please enter option choice :";
	 cin>>option;
	 cin.ignore();
	 switch (option)
	 {
		case '1': play();
				 break;
		case '2': wordmazeshow();
				 break;
		case 'q':cout<<"Quitting system"<<endl;
				 break;
		default: cout<<"you have entered an incorrect option choice please try again"<<endl<<endl;
	 }
  }
  while (option!='5');


	system("pause");

}
anyone?
1
2
3
4
5
6
7
8
9
10
class node
{
	public:
		int left;
		char data;
		int right;
};

node *start_ptr = NULL;
node *current_ptr;


Explain left and right to me. What do they represent? What is start_ptr and current_ptr and why are they never used?

In play where are row and column ever assigned values? What are Left and Right and why are they never assigned values? What is stacklist and why is it never assigned value(s)? Why do you have two variables in the same scope named tos? What is moves and why is it never assigned a value? What is stackobject1 and why is it never used?

In main what is the variable tos and why is it never used? Why are you looping on option != '5' when 'q' is the quit condition? main must return type int.
So Left and Right are to signify the players next move (for example, if the txt file reads "46 3 35" then the player must go either left or right, to either Left, which would be - row 4, col 6 or Right, which is - Row 3, col 5 and then store the Letter E in a separate stack)

start_ptr and current_ptr are currently not being used, but are there for later implementation (I meant to comment them out)

Stacklist is my stack, and I'm trying to store the letters from each move in there (to a maximum of 20 moves) tos is short for Top of Stack, there reason why there is 2 values assigned is that I'm not sure where to place it right now

Moves is a count of how many moves a player has made (they lose if it hits 20)

the last point is a typo, fixed now, thanks for helping.
Topic archived. No new replies allowed.