Would you please tell me the way to correct this kind of error ??
I have thought many many days and I simply cannot solve this . . . .
Unhandled Exception , access violation reading error
Code:
Code:
void win(Map*initialMap , Map* currentMap , int x , int y){
int i;
int j;
for(i=0; i < currentMap->height ; i++){
// all boxes are pushed into all targets
for(j=0; j < currentMap->width ; j++){
if (currentMap->map2D[y+j][x+i]=='@' && initialMap->map2D[y-j][x-i]=='!' ) <-- error
return ;
}
}
}
int try(Map *initialMap, Map *currentMap, int x, int y, int max_no_of_move, Stack *s) {
int i,j,k;
int result=0;
char q='\0';
char e[4]={NORTH,SOUTH,EAST,WEST};
Map tempmap;
if(max_no_of_move ==0 ) return 0;
win(&initialMap,¤tMap,&x,&y) return 1;
// if not , try each possible directions
for(i=0;i<4;i++){
if ( move_keeper(&initialMap,¤tMap,&x,&y,e[i])) {
clone_map(&tempmap,¤tMap);
result = try ( ¤tMap, &tempmap , x, y , max_no_of_move -1 , &s );
if(result) { return result;
//A solution is found
push(&s,e);
}
else {
q=pop(&s);
for(j=0;j<currentMap->width ; j++) {
for(k=0;k<currentMap->height;k++){
tempmap.map2D[k][j]=currentMap->map2D[k][j];
}}
}
return result;
}
}
}