I want my code to be able to ask for user how many planets the user wants to add to the array of planets, it asks the user how many in the beginning and store it as "numberofinputs" then use that to be the array size using malloc.
But it is giving me the error: request for member name( and dist, and decription) in something not in structure or union.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct{
char name[128];
double dist;
char description[1024];
} planet_t;
int numberofinputs;
int main() {
//creating the array
printf("How many courses: ");
scanf("%d", &numberofinputs);
int *solarsys=malloc(numberofinputs*sizeof(int));
int i;
char name[128];
printf("Enter planet name to add: ");
scanf("%s",name);
int have_planet = 0;
if(!have_planet){
for (i=0;i<numberofinputs; i++){
strcpy(solarsys[i].name, name);
printf("Enter distance and description: ");
scanf(" %lf ", &solarsys[i].dist);
gets(solarsys[i].description);
}
}
for(i=0; i<9; i++){
printf("%s %f %s\n",
solarsys[i].name,
solarsys[i].dist,
solarsys[i].description);
}
}