Unhandled Exception , access violation reading locations.

This is a discussion on Unhandled Exception , access violation reading locations. within the C Programming forums, part of the General Programming Boards category; Would you please tell me the way to correct this kind of error ?? I have thought many many days ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Unhandled Exception , access violation reading locations.

    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 . . . .

    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,&currentMap,&x,&y) return 1; 
    	  // if not , try each possible directions
    	for(i=0;i<4;i++){
    			if ( move_keeper(&initialMap,&currentMap,&x,&y,e[i])) {
    				 clone_map(&tempmap,&currentMap);
    				result  = try  ( &currentMap, &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;
    			}
    			}
    		
    	
    }
    Last edited by sokoban_1; 04-03-2010 at 02:14 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    OP needs to read << !! Posting Code? Read this First !! >>

    and this thread should be moved to C++ forum
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by vart
    and this thread should be moved to C++ forum
    I think this is C, not C++, otherwise there would have been a compile error due to the use of a keyword as a function name.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Indeed it is C . . .

    And I am thinking of the base case ( pushing all boxes into all targets .. )

    I am wondering if this code is correct or not . . .

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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 ;
    		}
    	}       
    }
    You need a simpler and more transparent one, imo.

    Code:
    int isWon(int currentMap, int offsetR, int offsetC, int maxRowGoal, int maxColGoal) {
      int r, c;
      int won = 1;  //assume game is won
    
      for(r = 0; r < maxRowGoal; r++) {
        for(c = 0; c < maxColGoal; c++) {
          if(currentMap[r+offsetR][c+offsetC] != answerMap[r][c]) {
            won = 0;
            break;
          }
        }
      }
      return won;
    }
    The offsetR/C gives the starting row and column, and maxRow/ColGoal, gives the ending coordinates. imo a function to check if the game is won, should return SOMETHING to signify if the game is won or not.

    I have this game (at least the first 50 levels of one version of it by "Thinking Rabbit"), and there are some levels of it that the solution just makes me laugh.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-17-2008, 08:45 AM
  2. Access Violation using memcmp?
    By someprogr in forum C Programming
    Replies: 3
    Last Post: 12-31-2007, 12:45 AM
  3. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  4. Unhandled exception error in VC++
    By tandirovic in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2005, 04:16 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21