w=(struct student *)malloc(sizeof(struct student));
p=head->next;
u=w->next;
while(p!=NULL) //把第一条链表中属于时间范围内的节点数据放进第三条链表
{ printf("a");
if((p->yue yue>qiyue)||(qiyue==zhongyue&&p->ri<=zhongri&&p->ri>=qiri)||(p->yue==qiyue&&p->ri>=qiri&&qiyue!=zhongyue)||(p->yue==zhongyue&&qiyue!=zhongyue&&p->ri<=zhongri))//判断是否在指点时间范围内
{
z=(struct student *)malloc(sizeof(struct student));printf("b");
strcpy(z->name,p->name);printf("c");
strcpy(z->class_name,p->class_name);printf("d");
strcpy(z->type,p->type);printf("e");
z->yue=p->yue;printf("f");
z->ke=p->ke;printf("g");
z->ri=p->ri;printf("h");
u->next=z;printf("i");
u=z;printf("j");
}
p=p->next;
}
这段代码是为了把一条链表里符合if语句里面条件的数据放到另一条链表里去
然后程序运行到输出i前面就停了,还没有报错
求解答
我已经找到了自己的错误了,应该把u=w->next;去掉加个u=w;
看起来问题可能是内存分配问题。您是否已检查过内存泄漏?
在分配内存时,您可能忘记将其初始化为NULL。因此,在访问其“next”字段时,程序可能会停止。您可以尝试在分配内存之后初始化为NULL,例如:
z=(struct student *)malloc(sizeof(struct student));
z->next = NULL;
您还可以在代码中加入一些调试信息,例如在每个printf语句之后打印一些信息,以查看在哪里发生了错误。