Malloc函数显示错误

时间:2015-12-19 13:18:27

标签: malloc

`struct node * createLL(struct node *head)
{   
int num;
struct node *new_node;
printf("enter the numbers you want to insert:\n");
printf("enter -1 to quit");
scanf("%d",&num);
while(num!=-1)
{
new_node=(struct node *) malloc (sizeof(struct node *));
new_node->data=num;
if(head==NULL)
{
new_node->next=NULL;
head=new_node;
}
else
{
new_node->next=head;
head=new_node;
}
printf("enter the numbers you want to insert:\n");
printf("enter -1 to quit");
scanf("%d",&num);
}
return head;
}`

用于为struct node *类型的链表创建new_node的malloc显示错误。它说" malloc未在范围内宣布" .. 我也提到了书......代码是一样的..无法弄清楚错误是怎么回事 可以纠正。

1 个答案:

答案 0 :(得分:2)

您确定在标题中包含了正确的库吗?确保包含

#include  <stdlib.h>