我用wc-tc编译了一段程序,可是提示有错误,我没有检查出来,帮帮我好吗

来源:百度知道 编辑:UC知道 时间:2024/06/30 09:26:29
struct node
{int data;
struct node *next;
};
typedef struct node SLIST;
SLIST *creat_slist()
{int c;
SLIST *h,*r,*s;
h=(SLIST *)malloc(sizeof(SLIST));
r=h;
scanf("%d",&c);
while(c!=-1)
{s=(SLIST *)malloc(sizeof(SLIST));
s->data=c;
r->next=s;
r=s;
scanf("%d",&c);
}
r->next='\0';
return h;
}
void print_slist(h)
{SLIST *p;
p=h->next;
if(p=='\0') printf("linklist is null");
else
{printf("head");
do
{printf("->%d",p->data);
p=p->next;
}while(p!='\0');
printf("THE END");
}
}
main()
{SLIST *h;
h=creat_slist();
print_slist(h);
getch();
}
你们太伟大了,我也是刚刚发现,都赖我太粗心,真的不好意思麻烦你们了。

修改一下函数定义void print_slist(struct node * h)

#include<stdio.h>
#include<stdlib.h>

struct node
{int data;
struct node *next;
};
typedef struct node SLIST;
SLIST *creat_slist()
{int c;
SLIST *h,*r,*s;
h=(SLIST *)malloc(sizeof(SLIST));
r=h;
scanf("%d",&c);
while(c!=-1)
{s=(SLIST *)malloc(sizeof(SLIST));
s->data=c;
r->next=s;
r=s;
scanf("%d",&c);
}
r->next='\0';
return h;
}
void print_slist(struct node * h)
{SLIST *p;
p=h->next;
if(p=='\0') printf("linklist is null");
else
{printf("head");
do
{printf("->%d",p->data);
p=p->next;
}while(p!='\0');
printf("THE END");
}
}
main()
{SLIST *h;
h=creat_slist();
print_slist(h)