Question: Structs and Arrays Below is a short code segment which is supposed to read in ints from the user and store them in the array

 Structs and Arrays Below is a short code segment which is

Structs and Arrays Below is a short code segment which is supposed to read in ints from the user and store them in the array of a bar struct. It prints out the entered numbers and then returns a pointer to the bar struct. Unfortunately, there are a number of errors in this code (compile, runtime, and logic). Identify at least 4 and briefly describe each error. 1 struct foo { 2 int size: 3 int *array: 4 } 5 6 typedef struct bar foo: 7 8 bar** readArray () { 9 bar *fbarrr = (bar *) malloc (sizeof(bar)): 10 *(fbarr - > array) = (in *) malloc (sizeof(int) * 100): 11 int i = 0: 12 int temp: 13 14 while (fscanf("%d", &temp) t = 0) { 15 *(fbarr + i) = temp: 16 i++: 17 } 18 19 (*fbarr).size = i: 20 21 printf("Numbers entered: "): 22 for (i = 0: i size: i++_ { 23 printf("%d", fbarr - > array[i]): 24 } 25 return &fbarr: 26 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!