 # Question & Answer: 1. Structs and Arrays (2 points) Below is a short code segment which is supposed to read in ints from the user and store them in the array of a….. looking for code errors

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: 1. Structs and Arrays (2 points) Below is a short code segment which is supposed to read in ints from the user and store them in the array of a…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

1. Structs and Arrays (2 points) 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. i struct foo f 3 int array 2 int size 6 typedef struct bar too; B bar* readArray( 9 bar barr (bar ) salloc sizeof (bar) 10 (fbarr-array)int malloc( sizeof (int) 100) 11 inti-0 12 int temp; 13 14 while scan ttexp) 0)r (fbarr )temp; 15 16 17 18 19 (fbarr).sizei 20 21 printf (“Numbers entered: ) 23 print”d “, fbarr->arrayi]); 24 25 return &fbarr; 26

struct f

{

int size;

int arry;

}

typedef struct bar f;

{
bar *fbarr *(bar*) malloc(size of(bar));

*(fbarr=>array)=(int*)malloc(sizeof(int)*100);

int i=0;

int temp;

while(fscanf(“%d”, &temp) i=0)

{

*(fbarr+1)=temp;

i++;

}

(*fbarr).size=i;

printf(“numbers entered:”);

for(i=0;i<=fbarr->size;i++)

{

printf(“%d”,fbarr->array{i});

}

return %fbarr;

}