Some questions with pointers
I am doing the card dealing function (from Deitel's C (thick) book)
The function receives the address of the shuffled deck to pick from, the address (the player's hand) and a pointer of the last card picked( ranges from 1 to 52).
Whenever the dealFive function is called it fills in the hand array with the 5 cards (suit and face in int), and should update the pointer's content, *iPtr.
So here's the code:
Code:
void dealFive(int wDeck[][13],int hand[5][2], int *iPtr){
int row, col;
for (;(*iPtr)<((*iPtr)+5); (*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;
}
}
}
}
}
I wish to use only pointer basics and arrays.
The problem is that the dereferenced pointer resets to 2 after incrementing from 4. The values of the pointed address messes up afterwards. The function does not terminate at all.
I must have made a mistake. I need advice with using pointers. Thank you.