I am having trouble figuring out how to get a value from a nested structure that is being passed into a function. I am trying the following:
13 int calcSize(struct rect **A) {
14
15 int test;
16
17 *A = malloc(sizeof(struct rect));
18
19 // (*A)->ne.x = (int *)malloc(sizeof(int));
20 test = (*A)->ne.x;
21 printf("%d",test);
22
23 return 0;
24
25 }
26
27
28 int main () {
29
30 int sum;
31
32 struct rect *input;
33 input = (struct rect*)malloc(sizeof(struct rect));
34 input->ne.x = 4;
35 input->ne.y = 6;
36 input->nw.x = 2;
37 input->nw.y = 6;
38 input->se.x = 4;
39 input->se.y = 2;
40 input->sw.x = 2;
41 input->sw.y = 2;
42
43 printf("%d",input->sw.y);
44
45 sum = calcSize(&input);
46
47
48 return 0;
49 }
I was looking for clarification regarding malloc'ing memory for this even though it's already defined? And also the dereferencing is a bit confusing given the nested structs and pointer.