为什么输入一个字符串之后按回车没有用,还是能输入,怎么搞的? C语言单向链表 15
#include<stdio.h>#include<stdlib.h>structstu{chara;structstu*next;};structstu*createl...
#include<stdio.h>
#include<stdlib.h>
struct stu{
char a;
struct stu *next;
};
struct stu *createlist()
{
char ch;
struct stu *head;
struct stu *t;
head=NULL;
ch=getchar();
while(ch!='\0')
{
t=(struct stu*)malloc(sizeof(struct stu));
t->a=ch;
t->next=head;
head=t;
ch=getchar();
}
return head;
}
void main()
{
struct stu *p,*q;
p=createlist();
while(p)
{
printf("%c\t",p->a);
q=p->next;
free(p);
p=q;
}
return;
} 展开
#include<stdlib.h>
struct stu{
char a;
struct stu *next;
};
struct stu *createlist()
{
char ch;
struct stu *head;
struct stu *t;
head=NULL;
ch=getchar();
while(ch!='\0')
{
t=(struct stu*)malloc(sizeof(struct stu));
t->a=ch;
t->next=head;
head=t;
ch=getchar();
}
return head;
}
void main()
{
struct stu *p,*q;
p=createlist();
while(p)
{
printf("%c\t",p->a);
q=p->next;
free(p);
p=q;
}
return;
} 展开
2015-09-21
展开全部
while(ch!='\0')
换成拦亩这个试试简虚森誉备
while(ch!='\n')
换成拦亩这个试试简虚森誉备
while(ch!='\n')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询