I'm trying to create an array of structs (of arrays) and am a bit unsure of the malloc required. First I define my struct,
typedef struct {
char *str1, *str2, *str3, *str4;
} player;
Then in main I need to initialize the structure, and malloc the strings inside of it,
player1 player;
player1.str1 = malloc(100);
// and the rest
But this is just for one structure. How do I malloc an array of these structures? Do I need to have a for loop and create N instances of the struct?
I'm guessing there's a line that's something like
playerArray* = malloc(N * sizeof(player))
The end goal is to have something I can access using, say,
printf("%s\n", playerArray[i].str1)
After I've read stuff into it. Thanks.
mallocthe array, tomallocthe strings.