how to pass value in one array to another array

I am writing code for a simple poker game. The problem I'm having is the proper use of pointers. I did look at the link below, as well as did some google research, but I am missing something and I know its something simple. would appreciate help.

Trouble deciphering function parameters: pointer and pointer to pointer

Ok i have a function that randomly generates the face and the value of the card. I want to pass this into an array as one string... so basically if wFace[column] is king and wSuit[row] is Heart. i want to pass king hearts to an array..player1... I can't figure out how to do that..here is what I tried..but it only collects the first value of face..it doesn't get the suit value.

When i try the code below the error I am getting is the following

73 35 E:\C++lab\pokerGame2.cpp [Error] incompatible types in assignment of 'const char*' to 'char* [5]'

I figure if i use a two dem array for player1 array..ie player1[][5]..I could pass the face value wFace[column] to wplayer1{here], and then pass the suit value..wSuit[row] to wplayer1[][here]. But I get the error I mentioned above. How can I do this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <stdio.h>	
#include <stdlib.h>
#include <time.h>
#include <iostream>



using namespace std;

void shuffle(int wDeck[] [13]);
void deal(const int wDeck[][13], const char *wFace[],
			const char *wSuit[], const char *wplayer1[][5], const char *wplayer2[]);

int main(void)
{
	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 char *player1[5][5];
	const char *player2[5];
							
	int deck[4][13] = {0};
	
	srand(time(0));
	
	shuffle(deck);

	deal(deck, face, suit, player1, player2);
	printf("\n");
	
	return 0;
}

void deal(const int wDeck[][13], const char *wFace[],
           const char *wSuit[], const char *wplayer1[][5], const char *wplayer2[]  )      
{	
	int card;
	int row;
	int column;
	int s;
		
	for(card =1; card <= 10; card++){
		
		if(card<=5){
		for(row = 0; row <= 3; row++){
			
			for(column = 0; column <= 12; column++){
				
				if(wDeck[row][column] ==card){//<<==problem
					wplayer1[card]= wFace[column], wSuit[row];
					cout<<wFace[column]<<" of "<<wSuit[row]<<"\n";
					      
				}		
			}
		} 
	}
		else if(card<=10){ 
			for(row = 0; row <= 3; row++){
			
			for(column = 0; column <= 12; column++){
				
				{if(wDeck[row][column] ==card){
					wplayer1[card]= wFace[column], wSuit[row];
				
					cout<<wFace[column]<<" of "<<wSuit[row]<<"\n";
					     
				     }
				
				
				}
			}
		} 
	}
}
	for(int i=1; i<=5; i++){
		cout<<"player 1 cards "<<wplayer1[i]<<endl;
	}
	
}
Last edited on
The problem points to you having a constant and trying to change it.
Constants are constants for the reason they cant be changed
Last edited on
but im not trying to change it.. its going from a const char to a const char...
regardless, the variable is still held in read only memory whether you are replacing it with constant or not it still cant change.

Here is a link to a set of in depth tutorial of how this works http://www.computerscienceforeveryone.com/Course_1/Unit_10/Lesson_1/

I'd also recommend viewing the complete set of tutorials as the explanation goes far deeper than any book or tutorial I have found thus far.
Last edited on
Topic archived. No new replies allowed.