我有一個產生錯誤的C程序:從無效轉換 '無效*' 到 '節點*'[-fpermissive]
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;
}
我是什麼做錯了?
你如何確保你正在編譯此爲C代碼,而不是C++代碼嗎? – nos
@Sildoreth請**不要**編輯帖子以改變編碼風格以適應您自己的主觀偏好。這只是破壞行爲,並不會幫助任何人。您的編輯應該永遠不會被批准。編輯回滾。 – Lundin
這就是說,這篇文章的縮寫是非常不一致的,需要修復。只需更改縮進即可進行編輯。 – Lundin