我正在尝试编写一个简单的c程序,但我无法声明“字符串”数组。以下代码编译时没有错误:
#define HAND_SIZE 10;
int main()
{
char * cards[13] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
int player[HAND_SIZE];
}
但是我不能让玩家变成一串“字符串”而不是整数。如果我执行以下任何操作:
char * player[HAND_SIZE];
char player [HAND_SIZE][];
char player [HAND_SIZE][5];
//repeat the above with '= {}' and '= {""}' initializations
我收到错误:
error: expected ‘]’ before ‘;’ token
为什么会发生这种情况?如何在c?
中声明一个空数组“字符串”答案 0 :(得分:1)
预处理程序指令不应以分号结尾。
#define
行结束后的分号给出了错误,这将有效:
#define HAND_SIZE 10
int main()
{
char * cards[13] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
int player[HAND_SIZE];
}