I want to read user's input for my array using pointers, allocated space, read elements and return pointer.
my function is called read:
Code:
double read *read_vector (int n) // n is the size of array, which user will enter
int *vec = (int *) malloc (sizeof(int)*n);
int i;
for (i=0; i<10; i++)
vec[i] = n;
return vec;
}
but this code is not working, giving me segmentation fault, any help please?
this is part of the main function i am using to read it:
Code:
int n;
double *vector;
/* Vector */
printf("Vector\n");
printf("Enter number of entries: ");
scanf("%d",&n);
printf("Enter %d reals: ",n);
vector = read(n);