Is there an equivalent solution similar to this implementation I've written in bash? Normally, I've always handled dynamic allocation like so:
(I like the second implementation because it's flexible and I don't need to know exactly how many inputs I need, I can input them as is. How can I accomplish a similar approach in C?
C Implementation:
double* get_data(int* data_size)
{
double* data_set = NULL;
int size = get_size();
int i;
*data_size = size;
data_set = malloc(size * sizeof(double));
for(i = 0; i < size; i++)
{
printf("Enter statistical data: ");
scanf("%lf", &data_set[i]);
}
return data_set;
}
Bash Implementation:
data_set=()
while IFS= read -r -p 'Enter statistical data (empty line to quit):' input; do
[[ $input ]] || break
data_set+=("$input")
done