I have 2 pointers declared like this:
void *arr1,*arr2;
I'm going to dynamically allocate memory for these 2 pointers and then scan some input to them. For instance, for the 1st one i do this:
scanf("%c",&typ);
scanf("%d",&len1);
The user enters the type of the input, and the size he wishes for the "array". My question is how to scan items to these arrays using scanf function. I tried this:
/*scan 1st array items*/
if(typ == 'i')
{
arr1 = (int*)malloc(len1 * sizeof(int));
for(i=0 ; i < len1 ; i++)
scanf("%d",arr1[i]);
}
if(typ == 'f')
{
arr1 = (float*)malloc(len1 * sizeof(float));
for(i=0 ; i < len1 ; i++)
scanf("%f",arr1[i]);
}
if(typ == 'c')
{
arr1 = (char*)malloc(len1 * sizeof(char));
for(i=0 ; i < len1 ; i++)
scanf("%c",arr1[i]);
}
/*end scanning 1st array*/
But i get these errors:
What am I doing wrong? Thank you