运行程序出现这个,为什么啊?
// 删除链表里值相同的多余节点
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#define SIZE sizeof(snode)
typedef struct student
{
int num;
struct student *next;
}snode;
snode *create1();
void print(snode *head); //打印链表
void del (snode *head);
void main(void)
{
snode *head;
head=create1();
printf("原链表为:\n");
print(head);
del(head);
printf("\n处理后链表为:\n");
print(head);
printf("\n");
}
snode *create1()
{
snode *head,*p,*q;
p=q=(snode *)malloc(sizeof(SIZE));
head=(snode *)malloc(sizeof(SIZE));
int n=0,num1;
FILE *fp;
fp=fopen("D:\\qq.txt","r");
fscanf(fp,"%d",&num1);
p->num=num1;
while(!feof(fp)) //
{
n++;
if(n==1)
head->next=p; //
else
q->next=p;
q=p;
p=(snode *)malloc(sizeof(SIZE));
fscanf(fp,"%d",&num1);
p->num=num1;
}
q->next=NULL;
return (head);
}
void print(snode *head)
{
snode *p;
p=head->next; //带头结点
while(p!=NULL)
{
printf("%6d",p->num);
p=p->next;
}
}
void del (snode *head)
{
snode *p, *s, *q;
p=head->next;
while(p!=NULL && p->next!=NULL)
{
s=p; //s指向要删除结点的前趋
q=p->next;
while (q!=NULL)
{
if(q->num==p->num)
{
s->next=q->next;
free(q);
q=s->next;
}
else
{
s=q;
q=q->next;
}
}
p=p->next;
}
}