#include
#include
struct character
{
int count;
char ch;
struct character *next;
};
bool flag = true;
char tmp;
struct character *creat_list()
{
printf("函数体内\n");
struct character *p1,*p2,*head;
p1=p2=(struct character *)malloc(sizeof(struct character));
tmp=getchar();
printf("函数体内输入之后\n");
p1->ch=tmp;
p1->count = 1;
head=NULL;
printf("打印p1->ch=%c\n",p1->ch);
while(p1->ch!='0')
{
printf("函数体内循环\n");
if(flag)
{
head=p1;
flag=false;
}
else
{
p2->next=p1;
}
p2=p1;
printf("打印p2->ch=%c\n",p2->ch);
p1=(struct character *)malloc(sizeof(struct character));
printf("下面进行输入\n");
tmp=getchar();
printf("输入完毕\n");
}
p2->next=NULL;
return head;
}
void main()
{
struct character *pt;
pt=creat_list();
while(pt!=NULL)
{
printf("%c\n",pt->ch);
pt=pt->next;
}
}
再循环内的输入会被跳过。为什么。
printf("下面进行输入\n");
tmp=getchar();
printf("输入完毕\n");