Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Segmentation fault (core dumped) in c I'm not sure whats wrong

Here is the code


typedef struct
char *maker;
char *model;
double oreading;
int date_of_manufacture;
int date_of_purchase;
int gas_tank_capacity;

void fill_struct (auto_t a);
void print_details (auto_t a);

int main(void)
auto_t a;
return 0;

void fill_struct(auto_t a)
printf("enter who makes the product: ");
a.maker = (char *)malloc(20*sizeof(char));
scanf("%s", &a.maker);
printf("enter the model: ");
a.model = (char *)malloc(20*sizeof(char));
scanf("%s", &a.model);
printf("enter the odometer reading: ");
printf("enter the date of manufacture: ");
scanf("%d", &a.date_of_manufacture);
printf("enter the gas_tank_capacity: ");
scanf("%d", &a. gas_tank_capacity);
printf("enter the date of purchase: ");
scanf("%d", &a.date_of_purchase);

return ;

void print_details(auto_t a)
printf("The maker of the product is %s",*a.maker);
printf("The model type is %s",*a.model);
printf("The odometer reading is %lf",a.oreading);
printf("The date of manufacture is %d",a.date_of_manufacture);
printf("The date of Purchase is %d",a.date_of_purchase);
printf("The Gas tank capacity is %d",a. gas_tank_capacity);


Sign In or Register to comment.