I'm new to pointers and this may be a silly question. Not able to store float numbers into float array using void pointer. Below is the code and the output:
Code:
int main()
{
int size=5;
float f_array[size];
populate(f_array, size);
// printing array below
}
void populate(void *p, int size)
{
int i;
for(i=0; i<size; i++)
{
scanf("%f", (((float *)p)+i));
}
}
Output:
//Entering five float numbers to be stored in array
1.2 // not able to enter other numbers and gives the below output
a[0] = 1
a[1] = garbage value
a[2] = garbage value
a[3] = garbage value
a[4] = 0
void populate(void *p, int size)before the main, else compiler could assume int for all your parameters: if 64 bit compiler you're toast.%dformat