如何在C中实现具有多个节点的链表?

时间:2015-05-10 21:27:50

标签: c pointers data-structures linked-list

我根据用户输入制作链接列表,如下所示:

vase1 = Button(root, relief=FLAT, background="white", image=imagepath)
......
_tkinter.TclError: image "C:\Users\- -\Desktop\Pythonproject\redvase.png" doesn't exist

现在,每个人都会How Many employees? 4 firstname lastnamerate,我会尝试使用这些输入并执行zipcode链接列表循环基于记录的数量,但我显然没有做到这一点:

for

我如何做到这一点?

1 个答案:

答案 0 :(得分:1)

要修复的示例

struct records {
    char first[20];
    char last[20];
    float rate;
    int zip;
    struct records *next;//typo struct node* next; 
};
int main(void){//return type is `int`
    int i, n;
    printf("Please indicate the number of records : ");
    scanf("%d", &n);

    struct records *head,*conductor;
    head=(struct records*)malloc(n*sizeof(struct records));
    for (i=0; i<n; i++){
        printf("\nEnter employee information in the format :\nFirstname Lastname rate Zipcode (newline for the next)\n");
        scanf("%19s %19s %f %d", head[i].first, head[i].last, &head[i].rate, &head[i].zip);
        head[i].next = &head[i+1];
    }
    head[n-1].next = NULL;

    return 0;
}