#include<stdio.h>
struct a
{
int element;
struct a *next;
};
void insert(int a,struct a *P)
{
struct a *TmpCell;
TmpCell =(struct a*)malloc(10);
TmpCell->element=a;
TmpCell->next=P->next;
P->next=TmpCell;
}
int main(void)
{
int b=1;
struct a *P;
P->next=NULL;
insert(b,P);
return 0;
}
起码贴一下运行日志啊。
目前我看到的错误有三个地方
malloc
函数需要引入stdlib.h
main
函数中的指针P
没有初始化TmpCell =(struct a*)malloc(10);
这里这样写不合理TmpCell =(struct a*)malloc(sizeof(struct a));
更好一些