0
`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函數顯示錯誤
'malloc'應在stdlib.h中聲明 - 你確定你做的#include''? –