在C中编译链接列表时出错



代码在编译时给了我错误,我不知道为什么这个问题是关于一家政策公司的,但与此无关只是为了让你了解我想做什么

我认为错误在的"(*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);

相关内容

  • 没有找到相关文章

最新更新