It's just a simple C program to display the array elements taken from the user but idk why am getting the garbage values when trying to print the array... if anyone could help i would really appreciate that... thanks!!
#include <stdio.h>
#include <stdlib.h>
double *array_dou;
double* initializeDoubles(int *maxdouble)
{
printf("Enter the max. double value the program should support: ");
scanf("%d",maxdouble);
array_dou = (double *) malloc((*maxdouble)*sizeof(double));
if(array_dou == NULL)
{
printf("Error! memory not allocated.");
exit(-1);
}
return array_dou;
}
int enterDouble(double *doubles,int dcount,int maxdouble)
{
for(dcount=0; dcount<maxdouble; dcount++)
{
printf("Please enter a double value: ");
scanf("%f",&doubles[dcount]);
}
return dcount;
}
int main()
{
int maxdouble;
int dcount=0;
double *doubles;
doubles = initializeDoubles(&maxdouble);
dcount = enterDouble(doubles,dcount,maxdouble);
printf("\nDouble array\n");
for(int j=0;j<dcount;j++)
{
printf("%lf ",doubles[j]);
}
return 0;
}