关于const 的问题
如果把两个指针数组前面的关键字 const 去掉, 编译器会报错。这是为什么?
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void shuffle (int [][13]);
void deal (const int [][13], const char * [], const char * []);
int main (void)
{
const char * suit[4] = {"Hearts", "Diamonds", "Clups", "Spades"};
const char * face[13] = {"Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King"};
int deck[4][13] = {0};
srand (time (NULL));
shuffle (deck);
deal (deck, face, suit);//不用 const 声明两个指针数组,这里会报错(VC6).
//不知道什么原因啊。。 请高手指点。。。
return 0;
}
void shuffle (int wDeck[][13])
{
int card, row, column;
for (card = 1; card <= 52; card ++)
{
row = rand() % 4;
column = rand() % 13;
while (wDeck[row][column] != 0)
{
row = rand() % 4;
column = rand() % 13;
}
wDeck[row][column] = card;
}
}
void deal (const int wDeck[][13], const char * wFace[],
const char * wSuit[])
{
int card, row, column;
for (card = 1; card <= 52; card++)
{
for (row = 0; row < 4; row++)
{
for (column = 0; column < 13; column++)
{
if (wDeck[row][column] == card)
printf ("%5s of %-8s%c", wFace[column], wSuit[row],
card % 2 == 0 ? '\n' : '\t');
}
}
}
}