So, I'm pretty inexperienced in C and am having trouble with this.
I have to initialize a certain number of objects as well as initialize two variables in each object. I have pre-written code that compiles and runs for a single object.
I had initially converted line:
MyObject object;
to
MyObject object[n]; //where n = # of objects needed
I altered other lines similarly such as:
mem = (unsigned char *)malloc( MEM_SIZE);
...
memset( &object, 0, sizeof(MyObect));
object.memory = mem;
to
mem = (unsigned char *)malloc(MAX_MEM_SIZE + (n*sizeof(MyObject)));
...
for( i = 0; i < n; i++){
memset( &object[i], 0, sizeof(MyObect));
object[i].memory = mem;
object[i].var1 = i;
object[i].var2 = n;
}
I keep getting a segmentation fault when I try to run the compiled program, even when I try to run it using only a single object and am not sure if it's a complete misunderstanding of what I want to do or something simple.