69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
typedef struct node{
char ch;
struct node *next;
}listnode;
typedef listnode *linklist;
listnode *p;
linklist create()
{
char ch;
linklist head;
listnode *p,*r;
head=NULL;
r=NULL;
while((ch=getchar())!='\n'){
p=(listnode*)malloc(sizeof(listnode));
p->ch=ch;
if(head==NULL)
{
r=head=p;
}
else
{
r->next=p; //这里有问题,求大侠帮忙解决
r=p;
}
if(r!=NULL)r->next=NULL;
}
return head; //返回一个头指针有什么作用?
}
main()
{
linklist newlist=create();
do{
printf("%c",newlist->ch);
newlist=newlist->next;
}while(newlist!=NULL);
}