输入功能分为链表

问题描述:

使用此功能时,我尝试做加(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; 

} 

我把当它要求它在我的信息后有问题的程序只是坐在那里,直到我将其关闭或它崩溃。

+0

请出示employeeData'的'的声明。 – dasblinkenlight 2014-09-22 21:08:48

+4

需要添加大量代码才能使任何人都能够复制此问题。 – 2014-09-22 21:10:02

+0

至少,add()函数的其余部分可能会有用。还是应该在'List = Head;'之后有一个右括号? – 2014-09-22 21:19:53

如果传递一个空指针到您add()功能则 该行的行为是不确定的,因为Temp设置为空指针:

Temp->next = List;