-1

I am trying to write a simple c program, but I am having trouble declaring "string" arrays. The following code compiles without error:

#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];
}

but I cannot make player into an array of "strings" instead of ints. If I do any of the following:

char * player[HAND_SIZE];

char player [HAND_SIZE][];

char player [HAND_SIZE][5];

//repeat the above with '= {}' and '= {""}' initializations

I get the error:

 error: expected ‘]’ before ‘;’ token

Why is this happening and how can I declare an empty array of "strings" in c?

1 Answers1

1

preprocessor directives should not end with a semicolon.

Semicolon after the end of #define line was giving you the error, This will work:

#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];
}
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Abhijith S
  • 526
  • 5
  • 17