新手请教哪地方出错,希望高手指出
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct Car
{
char maker[20];
int price;
};
struct Citizen
{
char* name; //姓名
int deposite; //存款
Car* car;//没车的时候用NULL来表示
};
void buy(Citizen* owner)
{
Car* car = (Car*)malloc(sizeof(Car));
strcpy(car->maker, "Chevrolet");
car->price = 10;
owner->car = car;
owner->deposite -= car->price;
}
void discard(Citizen* owner)
{
free(owner->car);
owner->car = NULL;
}
void sell(Citizen* owner, Citizen* other)
{
Car* car = owner->car;
car->price *= 0.5;
other->car = car;
owner->deposite += car->price;
owner->car = NULL;
}
int main()
{ int i;
struct Citizen duxuan = { "duxuan",30,NULL };
struct Citizen laowu = { "laowu",50,NULL };
buy(&duxuan);
printf("我的车名为%s\n该车花费为%d\n我剩余的存款为%d\n",duxuan.car->maker,duxuan.car->price,duxuan.deposite);
printf("1报废\n2出售\n");
scanf("%d",i);
if(i=1){
discard(&duxuan);
}
else if(i=2){
sell(&duxuan,&laowu);
}
return 0;
}