So to keep it short, I have a problem that is making me change around a pre-built program to include pointers.
It's a deck of cards and two hands.
I'm (trying) to make it so that instead of copying the values of the deck and putting them into the hand, I will just have the hand point to the card in the deck. I know it's not really how decks work, but the point of the exercise is just to get used to pointers, not the practicality of it (The way the program actually sets the decks makes me want to rip my hair out).
I almost have the basic syntax down of having a Ptr be set to the memory of the top of the deck, which is then stored into the hand.
However, the issue comes in when I have the hand array. The hand isn't equal to the deck memory, it's the next available memory, but it still has the same value, which means I'm not pointing to it, I'm copying it.
Here is the proto-function
int dealHand(int wDeck[][FACES], int *wHand[HAND], int top);
Here are the definitions and the call from main:
int *hand1[HAND] = {0};
int topDeck = 1;
topDeck = dealHand(deck, hand1, topDeck);
Here is the function:
int dealHand(int wDeck[][FACES], int *wHand[HAND], int top) {
size_t hand;
size_t row;
size_t col;
int *arrayPtr;
for (hand = 0; hand < HAND; hand++) {
for (row = 0; row < SUITS; row++) {
for(col = 0; col < FACES; col++) {
if (wDeck[row][col] == top) {
printf("%d %d\n", row, col);
arrayPtr = &(wDeck[row][col]);
wHand[hand] = arrayPtr;
printf(" DECK: %p\n", &wDeck[row][col]);
printf(" DECK: %d\n", wDeck[row][col]);
printf("POINTER: %p\n", arrayPtr);
printf("POINTER: %d\n", *arrayPtr);
printf(" HAND: %p\n", &wHand[hand]);
printf(" HAND: %d\n", wHand[hand]);
} // if
} // row
} // col
top++;
} // hand
return top;
}
wDeckandwHandare all redundantwDeck2-D array represent, and what isHANDand why?wDeck[0][4] == 6it means that the 5 of spades was the 6th card generated? What happens if the random numbers identify a card that has already been done?