I am trying to create an array of structures where each structure represents a celestial body for a problem that I am working on in my class. I donβt have such a lot of experience with structures, so I decided to try to use them instead of a number of arrays, however, I constantly encounter many different errors, although I tried to implement the methods that I saw in different streams and in stackoverflow (for example, in an Array of structures in C and C - to initialize an array of structs ), however, not all of them are applicable, so I could not completely copy the way to do this. Before I show you what I'm trying to do, I wonβt answer the comments / questions / answers for several hours, because I need to go to bed since I wake up too long, I really regret it, but I'm really tired after a busy day and have been working on this problem for several hours.
Additional information for those who read this: I do not need this to be dynamic, I know / determine the size of everything in advance. I also need it to be a global array (gasp GLOBAL VARIABLES ), since I access it in several ways that have certain arguments (i.e. GLUT methods).
This is how I define the structure in my header:
struct body { double p[3];
I have a list of other global variables that I define before I define the interior of the structure, and one of them is an array of this structure (basically, if I'm too unclear in my foggy conversation, the line is lower than above):
struct body bodies[n];
Just so you know, n is what I definitely defined (i.e. #define n 1 ).
I use this array in several ways, but the simplest and least expensive space is the simplified form of my main, where I initialize all the variables in each of the structures, just to set the variables for certain ones before changing them in some way:
int a, b; for(a = 0; a < n; a++) { for(b = 0; b < 3; b++) { bodies[a].p[b] = 0; bodies[a].v[b] = 0; bodies[a].a[b] = 0; } bodies[a].mass = 0; bodies[a].radius = 1.0; }
The current error I encountered is nbody.c:32:13: error: array type has incomplete element type , where line 32 is the place where I create the array of structures.
Thank you for any help you deign to give, I promise that I will get back to you very recently, in 12 hours.
The last refinement by title means the space above int main(void) , but in the same * .c file.