如下,编译可以过,运行不行,说内存不能为"read"或"written"
#include <stdio.h>
#include <stdlib.h>
struct link{
int n;
struct link* next;
};
struct link* create(void);
void main(){
struct link *head=create();
printf("Haha");
}
struct link* create(void){
struct link *head=NULL,*newlink,*tail;
int n=-1;
while(1){
printf("input the element:");
scanf("%d",&n);
if(n!=-1){
newlink=(struct link*)malloc(sizeof(struct link));
newlink->n=n;
if(head==NULL){
head->next=newlink;
head=tail=newlink;
return head;
}else{
tail->next=newlink;
return head;
}
}else{
return head;
}
}
}
如果知道怎么改的请说明下原理,谢谢