【发布时间】:2015-12-19 13:18:27
【问题描述】:
`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 未在范围内声明”.. 我也参考了书籍..代码相同..无法弄清楚错误是如何发生的 可以改正的。
【问题讨论】:
-
malloc应该在 stdlib.h 中声明 - 你确定你做了#include <stdlib.h>?
标签: malloc