I have this loop that gives seg. malfunction.
s->c = malloc(width * height * sizeof(double)); if (s->c == NULL) { puts("malloc failed"); exit(1); } for (int n = 0; n < width; n++) { for (int m = 0; m < height; m++) { d = (&s->c)[m][n]; printf("d %f\n", d); printf("m %i\n", m); printf("n %i\n", n); } }
Inside s-> c there is:
double* c;
When executed, it simply outputs:
d 27.000000 m 0 n 0
and then seg. malfunction.
This worked when I saw s-> c as a 1D array, but I would really like to treat it as a 2D array.
Is it possible when the c-pointer is in the structure?
If so, this is (&s->c)[m][n] , then the correct way to access elements?
Sandra
c ++ c
Sandra schlichting
source share