Thanks for the reply.
I have addressed the *iPtr+5 issue.
Code:
void dealFive(int wDeck[][13],int hand[5][2], int *iPtr){
int row, col;
int fivecards;
fivecards = (*iPtr)+5;
for (;(*iPtr)<fivecards; (*iPtr)++)
{
for (row =0; row < 4; row++)
{
for (col = 0; col < 13; col++)
{
if (wDeck[row][col]==(*iPtr))
{
hand[(*iPtr)][0] = row; //suit
hand[(*iPtr)][1] = col; //face
printf("Card %d: %d %d\n",*iPtr, row,col);
break;
}
}
}
}
}
What I did was to store the current *iPtr+5 to a variable.
Code:
Deck initialized. 1 2 3 4 5 6 7 8 9 10 11 12 13
---------------------------------------
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
---------------------------------------
Deck shuffled.
1 2 3 4 5 6 7 8 9 10 11 12 13
---------------------------------------
30 18 47 17 27 44 2 42 11 16 50 48 37
3 9 19 52 20 28 39 8 41 13 33 6 23
12 34 45 29 38 43 26 32 40 31 15 7 24
51 46 35 1 25 36 10 22 4 5 21 49 14
---------------------------------------
Card 1: 3 3
Card 2: 0 6
Card 3: 1 0
Card 4: 3 8
Card 3: 3 9
The above shows the runtime terminal.
Then, tracking the program, as the pointed value reaches 4, somewhere in the code, it becomes 3, but its the right card based on suit number and face number, and consequently, runs infinitely. I was wondering if the if statement using *iPtr, modifies it.
I want to practice the pass-by-reference by using pointers. In this function, the main program calls dealFive and sends the pointer. The address contains the number of cards picked from the shuffled deck, so when I call the deal function again, it won't start from the first card in the array, wDeck.
For instance, two players play a card game (like poker). Each player N (int handN[][]) would receive 5 cards from the shuffled deck. I thought that what if I would only pick a card? I thought of using pointer of the number of cards drawn until it reaches 52, incrementing it everytime a card is drawn/dealt.
Afterwards, I would add some logical check for "no more cards left".
I would appreciate some advice/changes for the code.
Again, thank you.