Always

something with programming :) I have encountered 2 things which my brain does not have any idea on how to handle.

The first one is seemly major(maybe minor)
1
2
3
A buffer overrun has occurred in mp7.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'. 


What in the heck is this ?

Another issue with this function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void deal(string playersName[],int cardsT[])
{
	int counter = 0;
	cout << "Deal two cards to everyone" << endl;
	for(int i = 0; i < TWOCARD; i++)
	{
		for( int j = 0; j < PLAYERCOUNT; j++)
		{
			cardsT[j] += hand[counter++].getFace();
		}

	}
	
	//Display
	for( int k = 0; k < PLAYERCOUNT; k++)
	{
		cout << "Hand for " << playersName[k] << " is : " ;
		hand[k].display();  
		cout << " and " ;
		hand[k + PLAYERCOUNT].display();
		cout << " Value for this hand is " << cardsT[k] << endl;
	}
	 cout << endl << endl;
}


This is supposed to according to my sample output

Hand for Andy is : JH QH Value of this hand is 20
Hand for Bob is : QC 2H Value of this hand is 12


Instead I get Value of this hand is 23 and for the second I get what appears like garbage 181832258.
It outputs about 7 lines like the example in bold one for each player but the only thing that is right is the hand of the cards like JH OH above.
The only think that I can think of is the array is not initialized but it is so that's where I part ways with solutions as of yet. The buffer problem I have absolutely no clue.
Hopefully someone else has a good idea of that the issue is thanks.
In deal() the counter variable has scope which global to the function. However, you are treating it as if it is local to the for loop. So what's happening is every time the function enters the second branch the counter gets incremented. This is not good because ultimatly you are going to over write the buffer, which is probably why you are getting your overflow error.

Compare this with a counter which is local to the for loop- everytime the function loops the variable is destroyed and re created.
Last edited on
Sorry I'm a little slow sometimes :)
1
2
3
4
5
6
7
8
int counter = 0;
	cout << "Deal two cards to everyone" << endl;
	for(int i = 0; i < TWOCARD; i++)
	{
		for( int j = 0; j < PLAYERCOUNT; j++)
		{
			cardsT[j] += hand[counter++].getFace();
		}

Your talking about this correct? I'm not sure what is wrong with it ? I was thinking that if that loop gets executed then the counter gets incremented? You are saying something different. I'm not sure I understand.
Topic archived. No new replies allowed.