I am trying to make an array of pointers to a structure the program runs, however it just says 'Segmentation fault: 11' any help would be be very much appreciated
typedef struct
{
int id;
double x;
double y;
char name[30];
int named;
} Star;
Star *stars[10];
int bang (int n_stars)
{
if ((n_stars >= 1) && (n_stars <= 10))
{
for (int i = 0; i < n_stars; i++)
{
double x = rand() % 10;
double y = rand() % 10;
stars[i] = (Star*) malloc(sizeof(x) + sizeof(y));
stars[i]->x = x;
stars[i]->y = y;
free(stars[i]);
return 1;
}
}
else
{
return 0;
}
return 0;
}