I have searched for a way to do this on my own, but I haven't found a situation that exactly matches mine and I'm not experienced enough to derive what to do from similar situations. So I'm hoping to get some help with my specific situation.
I have a struct, and I need to create 3 arrays of them. But when I allocate the memory using [], I run out of memory. So I think I need to use malloc; but I cannot figure out how to do it. Here is my code:
struct key {
char symbol[10];
int quantity;
char GroupID[10];
};
Then in main I have:
struct key PrevKeys= malloc(345000*sizeof(struct key));
struct key ActivityKeys= malloc(345000*sizeof(struct key));
struct key CurKeys= malloc(345000*sizeof(struct key));
But I keep getting "invalid initializer" error from the compiler.
Earlier I tried this, which compiled just fine but gave me a Seg Fault when I ran it (I'm assuming because I don't have enough memory in the stack):
struct key PrevKeys[345000];
struct key ActivityKeys[345000];
struct key Curkeys[345000];
Any ideas on how I can allocate these 3 arrays of structs would be very, very appreciated.