Trying to make it to where a struct array can be changed by typing out the requested limit. When I try to do this by making the array declaration a variable, it just says "Segmentation Fault(core dumped)"How can I fix this and allow the array to work? This is an example of the code I am trying to make:
#include <stdio.h>
struct Employee {
char firstName[20];
char lastName[20];
unsigned int age;
char gender;
double hourlySalary;
};
int main(){
int limit;
printf("How much employees do you wish to input\n");
scanf("%d", &limit);
int number = limit;
struct Employee Employ[number];
for(unsigned int i = 0; i < limit; ++i){
("\n\t Enter employee first name\n");
scanf("%s", &Employ[i].firstName);
("\n\t Enter employee last name\n");
scanf("%s", &Employ[i].lastName);
("\n\t Enter employee age\n");
scanf("%d", &Employ[i].age);
("\n\t Enter employee hourly salary\n");
scanf("%lf", &Employ[i].hourlySalary);
}
for(unsigned int i = 0; i < limit; i++){
printf("\n\tfirstname\tlastname\tage\thourlysalary\n%s\t%s\t%d\t%lf",Employ[i].firstName,Employ[i].lastName,Employ[i].age,Employ[i].gender,Employ[i].hourlySalary);
}
}
Expected results and input: