将功能输入到链表中

时间:2014-09-22 21:06:04

标签: c

当我尝试添加(myList)

时遇到此功能的问题
void add(struct employeeData *List)
{

    struct employeeData *Temp = NULL;
    struct employeeData *Head = NULL;

    Head = List;
    Temp = List;

    while (List != NULL)
    {
        List = List->next;

        if (List != NULL)
        {
            Temp = List;
        }

        else
        {
            break;
        }

    }

    List = (struct employeeData*)malloc(sizeof(struct employeeData));

    printf("Please enter the information of the employee");
    scanf(" %d %s %d %d %d ", &List->EMP_ID, List->name, &List->dept, &List->rank, &List->salary);

    Temp->next = List;
    List = Head;

}

在我询问它之后输入我的信息时,程序就坐在那里直到我关闭它或它崩溃。

1 个答案:

答案 0 :(得分:0)

如果将空指针传递给add()函数,则表示行为 此行未定义,因为Temp设置为空指针:

Temp->next = List;