Stack around the variable 'temp'

Hi, im making some of the exercises ive found on the net - a dungeon crawler. Sometimes i run in to a Stack around the variable 'temp' error, have no idea whats wrong :/ Sometimes i even get a buffer overrun, what do these errors mean?
Ive bolded where the error occurs. Heres the code:

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
#include <iostream>
#include <conio.h>
#include <time.h>
using namespace std;

char board[10][10];
int i,j;


void entities(int count, char type)
{
	while(count!=0)
	{
		int x,y;
		x=rand()%10;
		y=rand()%10;
		if((board[x][y]!='-') && (board[x][y]!=type))
		{
			while((board[x][y]!='-') && (board[x][y]!=type))
			{
				x=rand()%10;
				y=rand()%10;
			}
		}
		board[x][y]=type;
		count--;
	}
}

void print()
{
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			cout<<board[i][j]<<" ";
		}
		cout<<endl;
	}
}

void colorit()
{
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			board[i][j]='-';
		}
	}
}

void MoveE()
{
	char temp[10][10];
	int x,y,over=0;
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(board[i][j]=='E')
			{
				int px=i,py=j;
				board[i][j]='-';
				x=px+rand()%3-1;
				y=py+rand()%3-1;
				if((x!=px && y!=py) || x>10 || x<0 || y>10 || y<0 )
				{
					while((x!=px && y!=py) || x>10 || x<0 || y>10 || y<0 )
					{
					x=px+rand()%3-1;
					y=py+rand()%3-1;
					}
				}
				temp[x][y]='E';
			}
		}
	}

	for(int k=0;k<10;k++)
	{
		for(int q=0;q<10;q++)
		{
			if(temp[k][q]=='E')
			{
				board[k][q]='E';
			}
		}
	}
}

int MoveP()
{
	int x=-1,y=-1,over=0;
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(board[i][j]=='P')
			{
				x=i;
				y=j;
			}
		}
	}
	if(x==-1 && y==-1)
	{
		over=1;
	}
	else
	{
	char go;
	int xn,yn;
	cout<<"Where do you want to go?"<<endl;
	cout<<"WASD"<<endl;
	cin>>go;
	cout<<go<<endl;
	if(go=='w')
	{
		xn=x-1;
		if(xn>=0)
		{
			if(board[xn][y]=='T' || board[xn][y]=='E')
			{
				cout<<"Game Over!"<<endl;
				over=1;
			}
			else
			{
			board[x][y]='-';
			board[x-1][y]='P';
			}
		}
	}
	else if(go=='s')
	{
		xn=x+1;
		if(board[xn][y]=='T' || board[xn][y]=='E')
			{
				cout<<"Game Over!"<<endl;
				over=1;
			}
			else
			{
			board[x][y]='-';
			board[xn][y]='P';
			}
	}
	else if(go=='a')
	{
		yn=y-1;
		if(board[x][yn]=='T' || board[x][yn]=='E')
			{
				cout<<"Game Over!"<<endl;
				over=1;
			}
			else
			{
			board[x][y]='-';
			board[x][yn]='P';
			}
	}
	else if(go=='d')
	{
		yn=y+1;
		if(board[x][yn]=='T' || board[x][yn]=='E')
			{
				cout<<"Game Over!"<<endl;
				over=1;
			}
			else
			{
			board[x][y]='-';
			board[x][yn]='P';
			}
	}
	else
	{
		cout<<"Try again.."<<endl;
		system("pause");
		system("cls");
		MoveP();
	}
	}

	return over;
}

int wincheck()
{
	int count=0;
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(board[i][j]=='X')
			{
				count++;
			}
		}
	}
	return count;
}

int main()
{
	srand(time(0));
	colorit();
	entities(5,'T');
	entities(3,'E');
	entities(2, 'X');
	entities(1, 'P');
	print();
	int z=wincheck();
	while(z!=0)
	{
		system("cls");
		print();
		int zz=MoveP();
		if(zz==1)
		{
			break;
		}
		MoveE();
		MoveE();
		print();
		system("pause");
		system("cls");
		int z=wincheck();
	}
	z=wincheck();
	if( z==1)
	{
		cout<<"You won!"<<endl;
		system("pause");
	}
	return getchar();
}
The problem is not where you bolded. It is just signaled here because it is detected only where the overflowed buffer is freed.
I think your tests for x and y should be >=10 instead of >10 a few lines before what you bolded, since the max positions in temp are 9
Thanks, that solved the problem :) I even understood why >10 didnt cut it.
Last question/request - how does my code look? Maybe there was a better/faster way to make this? Just want to hear - yeah, its ok or go and study more ;)
Topic archived. No new replies allowed.