为什么有段语句编译器不能通过?
#include <stdio.h>#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define NULL 0
typedef struct LNode {
int data;
struct LNode *next;
}*LinkList;
LinkList creat(LinkList head)
{
LinkList l, q, p;
int ch;
l = (LinkList)malloc(sizeof(LinkList));
l->data = '\0';
l->next = NULL;
q = l;
p = l;
printf("Input the Incremental s:\n");
scanf("%d",&ch); //printf("%d\n",ch);
while (ch != 0)
{
p = (LinkList)malloc(sizeof(LinkList));
p->data = ch;
p->next = NULL;
q->next = p;
q = p;
scanf("%d",&ch);
//printf("%d\n",ch);
}
q = l;
return q;
}
LinkList Mergelist(LinkList A,LinkList B)
{
LinkList pa, pb, pc;
LinkList l;
l = (LinkList)malloc(sizeof(LinkList));
l->data = '\0';
l->next = NULL;
pa = A->next;
pb = B->next;
// pc = l->next;
while (pa && pb)
{
if (pa->data != pb->data)
{
pa = pa->next;
pb = pb->next;
}
else
{
pc = pa;
// printf("%d\n",pc->data);
pc = pc->next;
// printf("%d\n",pc->data);
pa = pa->next;
pb = pb->next;
}
}
pc = l;
while (pc->next != NULL)
{
printf(" %d",pc->next->data);
pc = pc->next;
}
return pc;
}// Mergelist
void Print(LinkList p)
{
LinkList q;
q = p;
if (p != NULL)
do {
printf(" %d",p->data);
p = p->next;
}
while (p != NULL);
}
int main()
{
LinkList a, b, c;
LinkList l;
l = (LinkList)malloc(sizeof(LinkList));
l->data = '\0';
l->next = NULL;
a = l;
b = l;
c = l;
a = creat(a);
b = creat(b);
c = Mergelist(a, b);
/*printf("Output the Descending series:\n");
c = c->next;
Print(c);*/
return 0;
}
此程序是想球俩个递增的A和B的交集C,而C也是以递增的方式输出~
上程序是莱鸟我编写的;但不能实现我的想法~我在调试的过程中(上程序是我调试的样本)发现:vc编译器不能通过:
while (pc->next != NULL)
{
printf(" %d",pc->next->data);
pc = pc->next;
}
在Mergelist函数中已经将A和B的交集赋值到C,但为什么打印不出来呢?~~此程序错在哪里呢??小弟搞了一个多星期了,还是不能解决,故发此贴向大家请教~~~先谢谢