错误编译 - 在C中的链表中

时间:2013-06-24 16:19:16

标签: c linked-list

代码在编译时给我错误,我不知道为什么 问题是关于一家政策公司,但这里没有任何关系 只是为了让你了解我想做什么

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

}

1 个答案:

答案 0 :(得分:7)

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

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

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