I have a problem with my code. I am creating a dynamic array and ask for some values. But when I print them on screen, the array seems uninitialized.
int main(void)
{
int i, j;
double *p;
printf("How much numbers?\n");
scanf("%d", &i);
p = malloc (sizeof(double)*i);
for(j = 0; j < i; j++)
{
printf("Set nr. %d :\n", j);
scanf("%f", p+j);
}
for(j = 0; j < i; j++)
{
printf("Nr. %d = %f\n", j, *(p+j));
}
}
I think the problem should be in this line, but i cannot figure out why?
scanf("%f", p+j);
I also tried this versions of code:
scanf("%f", (p+j));
scanf("%f", &p[j]);
Thank you!