manipulate a string into name of a variable?

Hello Everyone. I'm new to programming and I have some issue with my code:
I'm not really sure how that thing is called so it's hard to google it;
But I think human being will understand what I mean:

The while loop is increased by i++ each time. In the commented line I want to express

When
i = 1 , player1.cards[j] = random;
i = 2 , player2.cards[j] = random;

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
void cardScramble()
{
int random;
int i = 1;
while (i <= 4)
{
cout << "Card of Player " << i << " : ";
int j = 0;
while (j < 13)
{
random = rand() % 52;
if (cards[random] == NULL)
{
cards[random] = i;
cout << cardName(random) << " , ";
/*	 player(i).cards[j] = random; */
/* That's what I'm doubt with */
j++;
}
}

cout << endl;
i++;
}
return;
}


I tried to define it or manipulate it as a string but didn't work.
Anyone can help me on this? Thanks a lot!
You could define player as a struct array.

If you create a structure like this one:
1
2
3
struct PlayerCards{
int cards[52];
};

And declare "player" as struct PlayerCards player[5];, you can write player[i].cards[j] = random;.
In c++, you can't use a string literal as a variable name unless you write code to do that yourself.
Topic archived. No new replies allowed.