Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

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

$
0
0
Here is the code


#include <stdio.h>
#include <string.h>
#include <malloc.h>

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;
}


Viewing all articles
Browse latest Browse all 2703

Trending Articles