首页 > 解决方案 > 错误:第 24 行的 '->' 标记之前应为 ';'、',' 或 ')'

问题描述

/*Add a new node to the top of the list*/
        firstlist  *insert_top(char entry->name, char entry->address, int entry->phone, firstlist*head)
        {


            firstlist *new_node;
            new_node=(firstlist*)malloc(sizeof(firstlist));
            new_node->name=entry->name;
            new_node->address=entry->address;
            new_node->phone=entry->phone;
            new_node->next=head;
            head=new_node;
            return head;

        }

我在第 24 行遇到此错误:错误] 在 '->' 标记之前预期有 ';'、',' 或 ')'

https://pastebin.com/LsNwAgQE

希望大家帮忙。

标签: c

解决方案


您需要entry->nameinsert_top函数定义中删除 。

有2种方式可以通过。作为一个结构:

firstlist  *insert_top(firstlist *entry, firstlist*head)

那么您可以使用entry成员,例如entry->name

并稍后调用它:

head=insert_top(entry, head);

另一种选择是使用单独的值:

firstlist  *insert_top(char name, char address, int phone, firstlist *head)

那时,您无法使用,entry->name因为您的函数不知道条目是谁,只需使用name

调用insert_top此选项与您所做的相同:

head=insert_top(entry->name, entry->address, entry->phone, head);

推荐阅读