Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

billcozbeebillcozbee Posts: 2Member
Here is the code


#include
#include
#include

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

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

int main(void)
{
auto_t a;
fill_struct(a);
print_details(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: ");
scanf("%lf",&a.oreading);
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);

return;
}

Sign In or Register to comment.