I'm trying to create an array of strings inside a struct which represents a player's inventory.
I create a struct for the player:
typedef struct Player {
char *inventory[];
} Player;
And then I use a function which allocates heap memory and creates (not sure if "create" is the right word here) the struct with some "items" inside the player's "inventory".
Player *spawnPlayer(void)
{
Player *stats = malloc(sizeof(Player));
stats->inventory[] = {"potion", "potion", "ether"};
return stats;
}
Now I can create a normal array like this outside of a struct, but if I attempt to use the above, I get the below error while trying to compile:
arrays.c: In function 'spawnPlayer':
arrays.c:13:19: error: expected expression before ']' token
stats->inventory[] = {"potion", "potion", "ether"};
Would someone be able to point me in the right path as to why this doesn't work?