You are using a version without Ads of this website. Please, consider donating:

### 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:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238`` ``````#include #include #include 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<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?"<>go; cout<=0) { if(board[xn][y]=='T' || board[xn][y]=='E') { cout<<"Game Over!"<
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.