Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 链表编译时错误_C - Fatal编程技术网

C 链表编译时错误

C 链表编译时错误,c,C,在下面的代码中,我在编译时在add_节点函数中遇到了问题 我收到一个与以下代码行相关的错误:struct*node pNode=struct node*mallocsizeofstruct node 如有任何建议,将不胜感激 struct list { struct node *head; int count; }; struct node *add_node(struct list *pList, float coef, int expo) { if (pList ==

在下面的代码中,我在编译时在add_节点函数中遇到了问题

我收到一个与以下代码行相关的错误:struct*node pNode=struct node*mallocsizeofstruct node

如有任何建议,将不胜感激

struct list
{
   struct node *head;
   int count;
};

struct node *add_node(struct list *pList, float coef, int expo)
{
    if (pList == NULL)
    {
        return NULL;
    }

    struct *node pNode = (struct node*)malloc(sizeof(struct node));

    if (node == NULL)
    {
         return NULL;
    }

    pNode->coef = coef;
    pNode->expo = expo;
    pNode->link = pList->head;

    pList->head = pNode;
    pList->count++;

    return pNode;
}
做这个

struct *node pNode = (struct node*)malloc(sizeof(struct node));


您可能需要将行更改为struct node*pNode=struct node*mallocsizeofstruct node

变化

if (node == NULL)


感谢这项工作,但另一个问题出现在以下行中;如果node==NULL,则错误表示该节点为空undeclared@user4225083您需要在pNode上执行健全性检查,而不是节点。永远不要强制转换malloc returns。请说明您遇到的错误。一个错误可能是磁盘已满-按任意键继续。我这样做了,它可以工作,但一个新的错误声称我有一个未定义的对main的引用;collect2:ld返回了1个出口status@user4225083:那么以上就是你的整个计划?C需要一个主函数。我想是时候回到你的学习手册了。你忘了主要功能了。好的,回到我的书上,谢谢大家的帮助。
if (node == NULL)
if (pNode == NULL)