这是我用C写的一个链表程序,完成的功能是创建一个链表和输出一个链表,可到输出的时候总是有Null pointer assignment的错误信息,没有办法现在都已经是凌晨4:40了为了这个问题睡不着觉,请大家帮帮我吧,我的源程序如下:(我的Email:txbhj@163.com)
输入0代表链表结束
#define LEN sizeof(struct List)
#define TRUE 1
#define ERROR 0
#define FALSE 0
#define NULL 0
#include "malloc.h"
typedef int ElemType;
struct List{ ElemType elem; int size; struct List *next; };
struct List *creat(void){ struct List *head; struct List *p,*p1,*p2; p1=p2=(struct List *)malloc(LEN); scanf("%d",&p1->elem); p=head=NULL; while(p1->elem!=0){ p->size=+1; if(p->size==1)head=p1; else p2->next=p1; p2=p1; p1=(struct List *)malloc(LEN); scanf("%d",&p1->elem); } p2->next=NULL; return(head); }
void print(struct List *head){ struct List *p; printf("The records are:"); p=head; if(head!=NULL) do {printf("%d ",p->elem); p=p->next; }while(p!=NULL); }
main(){ struct List *head; head=creat(); print(head); }
![](images/smilies/emot/em03.gif)
![](images/smilies/emot/em03.gif)
![](images/smilies/emot/em03.gif)
[此贴子已经被作者于2005-8-7 4:52:44编辑过]