在下面的代码中,我在编译时在add_node函数中遇到问题。
我收到与以下代码行有关的错误:struct *node pNode = (struct node*)malloc(sizeof(struct 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;
}
答案 0 :(得分:2)
制作本
struct *node pNode = (struct node*)malloc(sizeof(struct node));
到
struct node *pNode = (struct node*)malloc(sizeof(struct node));
答案 1 :(得分:0)
您可能想将该行更改为struct node * pNode =(struct node *)malloc(sizeof(struct node));
答案 2 :(得分:0)
更改
if (node == NULL)
到
if (pNode == NULL)