I declared a struct which is supposed to be a pixel and it has 3 properties (x, y location and F intensity) like this:
struct pixel {
int F, // intensity from 0-255
x, // horizontal component
y; // vertical component
};
Then I declared an 2D array of type pixel (the struct above) like this:
int N=100;
pixel image[N][N];
Then I used the following loop to assign values to x and y:
int count, k;
for (int i=0 ; i<N ; i++)
for (int j=0 ; j<N ; j++)
{
k = j + i*N;
image.x[k] = count;
count++;
}
What did I do wrong?
The line
is incorrect. You declared a 2D array of pixels:
The way to access an element of the array is as follows:
You do not need to calculate the flat index k yourself.