| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Another strange error
I an making a Connect 4 game, and when I go to make a move after I sucessfully compiled it, it gives me this error:
Debug Error! Program: C:\My C++ Stuff\Connect 4\Debug\Connect 4.exe DAMAGE: after Normal block (#64) at 0x00441500 (Press Retry to debug the application) I tried to debug it, but have no idea how, and ignore seems to work, but the error keeps coming back every time you enter a move. I am using Visual C++ 97, Windows 2000. This is the source code: //Connect 4 //The C++ Version of the popular game //Programmed by Anlu Wang #include <iostream> #include <stdlib.h> #include <time.h> #include <apstring.h> void init(void); //Initialize stuff void display(void); //Display board void makeMove(void); //Make a move void testWin(void); //Test for win int board[6][7]; //6 rows, 7 cols int turn = 1;//1 - Player 1, 2 - player 2 int win = 0;//not used yet apstring p1Name;//string for p1 name apstring p2Name;//string p2 name int main(){ cout << " ,/-----/ [\\ [\\" << endl << " ,/--/'''' [ ] [ ]" << endl << " /--/ [ ] [ ]" << endl << " |--| /===\\ {}`` {} []\" [] /----> /^^^^ <==^==> [ ] [ ]" << endl << " |--| [|---|] {}`` {} [] \" [] | () [:] [ ] [ ] " << endl << " |--| || || {} ``` {} [] \" [] |---> () [:] [ \\____/ ]" << endl << " |--| [|---|] {} ``{} [] \" [] | () [:] \\_______ ]" << endl << " \\--\\ \\===/ {} ``{} [] \"[] \\----> \\vvvv \\-/ [ ]" << endl << " `\\--\\,,,, [ ]" << endl << " `\\------\\ Programmed By [my name here] \\]" << endl; init(); while(win == 0){ display(); makeMove(); testWin(); } return 0; } void init(void){ char choice; for(int i = 0;i<6;i++){ for(int j = 0;j<7;j++) board[i][j] = 0; } cout << "\nWelcome to Connect 4. Would you like instructions? (Y or N)"; cin >> choice; if(choice == 'y' || choice == 'Y'){ cout << "\nConnect 4 is a game played on a 10 by 10 grid. The object is to get" << endl << "4 of your pieces in a row by dropping them from the top of the grid." << endl << "The 4 pieces can be aligned up, down, of diagonally and when dropped," << endl << "the pieces will travel in a straight line down the grid until it hits" << endl << "the bottom of the grid. The game itself is very simple, but difficult" << endl << "to master (Wow, I sound cheesy). Player 1's symbol is '0' and Player 2's" << endl << "symbol is 'O'. Currently there is no AI, but it may be added soon." << endl; } cout << "What is player 1's name? "; cin >> p1Name; cout << "What is player 2's name? "; cin >> p2Name; return; } void display(void){ cout << " "; for(int i = 0;i<=6;i++) cout << i << " "; cout << endl; cout << "---------------" << endl; for(i = 0;i<6;i++){ for(int j = 0;j<7;j++){ if(board[i][j] == 1) cout << "|0"; else if(board[i][j] == 2) cout << "|O"; else cout << "| "; } cout << "|"; cout << endl << "---------------" << endl; } return; } void makeMove(void){ int move; int row = 0; Move: if(turn == 1) cout << p1Name + "'s move? "; if(turn == 2) cout << p2Name + "'s move? "; cin >> move; if(move > 6 || move < 0 || board[row][move] != 0){ cout << "ILLEGAL MOVE" << endl; goto Move; } while(board[row][move] == 0){ if(turn == 1){ board[row][move] = 1; board[row-1][move] = 0; } if(turn == 2){ board[row][move] = 2; board[row-1][move] = 0; } row++; } if(turn == 1) turn = 2; if(turn == 2) turn = 1; return; } void testWin(void){ return; } If you need any more info, just ask. |
|
#2
|
|||
|
|||
|
Ok its unlikely anyone here will do your debugging for you but I can give you some advice on how to go about it yourself.
Go through your program and add some printf/cout lines that print out an explanation of where they are and the values of the variables around them. Then run your program and use them to narrow down the line(s) that are causing the error. If you have access to a proper debugger and the time to learn to use it go for it but in a lot of cases this will be just as effective but take a bit longer. (Well longer than using the debugger once you know how it works anyway.) Once you've done this you will be in a much better position to fix the error or be far more specific with you questions and thus far more likely to get someone to find it for you. Hope this helps, -KM- |
|
#3
|
|||
|
|||
|
My programs fine now, it just spontaneously worked one day...
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Another strange error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|