CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Jun 2005
    Posts
    181

    Debugging Arrays

    I want to change the results of function deal() below which fills out a string array. In the watch window I can change the result of the memory location that the pointer points to, but not the string that begins at that address.

    Is it possible to keep the memory location the same but alter the string?

    Code:
    #include <iostream>
    
    using std::cout;
    using std::left;
    using std::right;
    
    #include <iomanip>
    
    using std::setw;
    
    #include <cstdlib>
    #include <ctime>
    
    void shuffle( int[][13]);
    void deal(const int [][13], const char *[], const char *[], const char *[][2]);
    bool Pair( const char *[][2], int);
    bool TwoPair(const char *[][2], int);
    
    
    int main()
    {
    	const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
    
    	const char *face[13] = { "Ace","Deuce","Three","Four",
    		                     "Five", "Six", "Seven", "Eight",
    							 "Nine", "Ten", "Jack", "Queen", "King"};
    
    	const int Size=5;
    	bool pairRes =false;
    
    	int deck[4][13] = {0};
    	const char *hand[Size][2];
    	
    
    
    	srand(time(0));
    
    	shuffle( deck );
    	deal( deck, face, suit, hand);
    	pairRes = Pair(hand, Size);
    
    
    	return 0;
    }
    
    void shuffle(int wDeck[][13])
    {
    	int row;
    	int column;
    
    	for ( int card =1; card <= 52; card++){
    
    		do {
    			row = rand() % 4;
    			column = rand() % 13;
    		} while ( wDeck[row][column] != 0);
    
    		wDeck[row][column] =card;
    
    	}
    
    }
    
    void deal( const int wDeck[][13], const char *wFace[], const char *wSuit[], const char *hand[][2])
    {
    	for ( int card =1; card <= 5; card++)
    
    		for ( int row = 0; row <=3; row++)
    
    			for ( int column =0; column <=12; column++)
    				
    				if ( wDeck[row][column] == card) {
    					hand[card-1][1] = wSuit[row];
    					hand[card-1][0] = wFace[column];
    				}
    }
    
    bool Pair( const char *hand[][2], int Size)
    {
    	for ( int i = 0; i < Size; i++)
    
    		for ( int j = i+1; j< Size; j++)
    
    			if ( hand[i][0] == hand[j][0])
    
    				return true;
    			
    				return false;
    }
    
    bool TwoPair( const char *hand[][2], int Size)
    {
    	int counter =0;
    	
    	for ( int i = 0; i < Size; i++)
    
    		for ( int j = i+1; j< Size; j++)
    
    			if ( hand[i][0] == hand[j][0])
    
    			{counter++;
    			if (counter == 2)
    				return true;}
    			
    				return false;
    }
    Last edited by Bazman; August 2nd, 2008 at 06:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured