C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 17th, 2004, 02:12 PM
Xx Shinwa xX Xx Shinwa xX is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: In the Universe
Posts: 3 Xx Shinwa xX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Xx Shinwa xX
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.

Reply With Quote
  #2  
Old August 18th, 2004, 03:24 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
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-

Reply With Quote
  #3  
Old August 18th, 2004, 04:56 PM
Xx Shinwa xX Xx Shinwa xX is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: In the Universe
Posts: 3 Xx Shinwa xX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Xx Shinwa xX
My programs fine now, it just spontaneously worked one day...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Another strange error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway