我有一个产生错误的 C 程序:
invalid conversion from 'void*' to 'node*' [-fpermissive]
这是我的代码:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
struct node* onetwothree();
int main()
{
struct node* ptr;
ptr = onetwothree();
return 0;
}
struct node* onetwothree()
{
struct node* head;
struct node* temp;
head = malloc(sizeof(struct node));
temp = head;
for(int i=1; i<=3; i++)
{
temp->data = i;
if(i<3)
temp=temp->next;
else
temp->next = NULL;
}
return head;
}
我究竟做错了什么?