Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dynamic arrays Problem in C (NOT ++)- Create perfectly sized arrays to hold data

ID: 3829907 • Letter: D

Question

Dynamic arrays Problem in C (NOT ++)- Create perfectly sized arrays to hold data using malloc and realloc. Your program should contain one malloc-ed array for the following types: Integer Double Character String For this problem, the user should be allowed to enter an unlimited amount of integers, doubles, characters, or strings. Your program should identify which type of input was received, and dynamically allocate space for it in its proper array (realloc). The contents of all four arrays should be displayed to the user after each entry. Examples:

Enter your input: 1

String List:

Integer List : 1

Double List:

Character List:

Enter your input: 7.6

String List:

Integer List : 1

Double List: 7.6

Character List:

Enter your input: apples

String List: apples

Integer List : 1

Double List: 7.6

Character List:

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>


int main(){

int i;
char *c;
char buffer [256];
double d;


printf ("Enter your input: ");

fgets (buffer, 256, stdin);

i = atoi (buffer);
d = atof (buffer);
c = buffer[0];

printf ("String List:%s",buffer);
printf ("Integer List:%d ",i);
printf ("Double List:%f ",d);
printf ("Character List:%c ",c);
  

  

return 0;

}