Problem with Multidimensional array

Hey all, I keep getting the following error message when I try to copy values from one array to another:

error: expression must have pointer-to-object type

This is a piece of the relevant code to which it refers:

1
2
3
4
5
	for(int j = 0; j < 5; ++j){
		for(int k = 0; k < 5; ++k){
			host_R[j][k] = R[j][k];
		}
	}


where R[j][k] has all its values set and I just want to copy them into host_R[j][k]

I also get the same error message at this point:

1
2
3
4
5
6
7
	for(int p = 0; p < N; ++p){ //For all particles
		for(int i = 0; i < 5; ++i){ //Matrix i component
			for(int j = 0; j < 5; ++j){ //Matrix j component
				float X[p] = r[0][0]*x[p] + r[1][0]*p_x;
			}
		}
	}


Any help would be greatly appreciated.
Thanks
Did you mean
 
X[p] = r[0][0]*x[p] + r[1][0]*p_x;

on line 4?
A little whitespace could go a long way to making those more readable. Just a thought.
Thankyou for your constructive criticism moorecm.
helios - yes sorry i meant what you wrote.
How are those arrays defined?
Sorry I was away at the weekend, but here is enough code that should hopefully cover it all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        const int max_particles = 1000;

	struct element{
		float x[max_particles]; //Transverse horizontal position
		float p_x[max_particles]; //transverse horizontal momentum
		float y[max_particles]; //Transverse vertical position
		float p_y[max_particles]; //Transverse vertical momentum
		float t[max_particles]; //Time of flight relative to ideal reference particle
		float p_t[max_particles]; // (Delta)E/(p_s*c)  i.e. Energy relative to reference particle divided by the product of the nominal momentum of an on-energy particle and the velocity of light
	} particle; //The struct object for the elements of particles is called particle

	//Define the transport matrix R
	float R[6][6] = {0}; //initialise the transport matrix R to all zero values
	float Beta = 0.8; //Assign a value to relativistic Beta (Obviously this will be determined by program at a later stage)
	float Gamma = 1.666; //As above for relativistic Gamma
	float L = 100.0; //Length of the drift space


	//To start with, we need to change the value of R to match a purpose, as at the moment it is set to all zeros
	//For now, we will make it equal to the drift matrix
	for(int j = 0; j < 5; ++j){ //Remember that the first matrix element begins at zero so the last is the 5th element
		R[j][j] = 1.0; //Sets the diagonals to 1
	}
	R[1][0] = R[3][2] = L;
	R[5][4] = L/(Beta*Beta*Gamma*Gamma);

	float X[max_particles] = {0};
	float P_X[max_particles] = {0};
	float Y[max_particles] = {0};
	float P_Y[max_particles] = {0};
	float T[max_particles] = {0};
	float P_T[max_particles] = {0};

	//Now we need to create variable arrays to store the results before returning them to the host
	for(int p = 0; p < N; ++p){ //For all particles
		X[p] = R[0][0]*x[p] + R[1][0]*p_x[p] + R[2][0]*y[p] + R[3][0]*p_y[p] + R[4][0]*t[p] + R[5][0]*p_t;
		P_X[p] = R[0][1]*x[p] + R[1][1]*p_x[p] + R[2][1]*y[p] + R[3][1]*p_y[p] + R[4][1]*t[p] + R[5][1]*p_t;
		Y[p] = R[0][2]*x[p] + R[1][2]*p_x[p] + R[2][2]*y[p] + R[3][2]*p_y[p] + R[4][2]*t[p] + R[5][2]*p_t;
		P_Y[p] = R[0][3]*x[p] + R[1][3]*p_x[p] + R[2][3]*y[p] + R[3][3]*p_y[p] + R[4][3]*t[p] + R[5][3]*p_t;
		T[p] = R[0][4]*x[p] + R[1][4]*p_x[p] + R[2][4]*y[p] + R[3][4]*p_y[p] + R[4][4]*t[p] + R[5][4]*p_t;
		P_T[p] = R[0][5]*x[p] + R[1][5]*p_x[p] + R[2][5]*y[p] + R[3][5]*p_y[p] + R[4][5]*t[p] + R[5][5]*p_t;
	}



the variables x, p_x, y, p_y, t, p_t have all their values read into them by a file, and I am confident that that bit works correctly.
N is the number of particles as counted when inputting the data from file.
Hope this helps, and thanks again
Topic archived. No new replies allowed.