我使用swapCardsRandomly(b)
但是当我尝试swapCardsRandomly(*b)
程序时仍然可以正常工作,没有任何问题。
那有什么区别呢?
/*
*shuffles cards randomly
*/
void shuffle( int b[][13] ) {
int counter;
int rand1 = rand() % 4;
int rand2 = rand() % 13;
b[rand1][rand2] = 1;
counter = 2;
while ( counter < 53 )
{
rand1 = rand() % 4;
rand2 = rand() % 13;
while ( b[rand1][rand2] != 0 )
{
rand1 = rand() % 4;
rand2 = rand() % 13;
}
b[rand1][rand2] = counter++;
}
swapCardsRandomly( b );
}
//for better shuffling swap elements randomly
void swapCardsRandomly( int m[][13] ) {
int temp;
int rand1;
int rand2;
for ( i = 0; i < 4; i++ )
{
for ( j = 0; j < 13; j++ )
{
rand1 = rand() % 4;
rand2 = rand() % 13;
temp = m[i][j];
m[i][j] = m[rand1][rand2];
m[rand1][rand2] = temp;
}
}
}