C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Segmentation fault (core dumped) in c I'm not sure whats wrong Posted by billcozbee on 4 Dec 2012 at 1:35 PM
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;
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.