gpt4 book ai didi

c - 编译错误 - 在 C 的链接列表中

转载 作者:行者123 更新时间:2023-11-30 21:45:27 26 4
gpt4 key购买 nike

代码在编译时给我错误,我不知道为什么问题是关于一家保单公司的,但与这里无关只是为了让您了解我正在尝试做什么

我认为错误出现在“(*h)=temp”行

typedef struct
{
char cmp_name[20];
int pol_code;
float pol_price;
int drivers;
float new_d;
float old_d;
} POL;

typedef struct node
{
POL policy;
struct node *next;
} NODE;

void ins(NODE **h,NODE *p)
{
NODE *temp;
temp=(NODE*)malloc(sizeof(NODE));

if(p==NULL)
{
(*h)=temp;
temp->next=NULL;
}
else
{
p->next=temp;
p=p->next;
temp->next=NULL;
}

printf("\nEnter Company Name: ");
scanf("%s",temp->policy.cmp_name);
printf("\nEnter Policy Code: ");
scanf("%d",temp->policy.pol_code);
printf("\nEnter Policy Price: ");
scanf("%f",temp->policy.pol_price);
printf("\nEnter Number of Drivers: ");
scanf("%d",temp->policy.drivers);
printf("\nAddon for a New Driver: ");
scanf("%f",temp->policy.new_d);
printf("\nAddon for a Old Driver: ");
scanf("%f",temp->policy.old_d);

}

最佳答案

NODE *temp; // This variable is uninitialized. It "points" to a region you haven't allocated.

然后你在这里取消引用它:

scanf("%s",temp->policy.cmp_name);

关于c - 编译错误 - 在 C 的链接列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com