当前位置: 代码迷 >> C语言 >> [求助]gets()与scanf()函数有冲突?
  详细解决方案

[求助]gets()与scanf()函数有冲突?

热度:569   发布时间:2007-06-11 22:52:25.0
[求助]gets()与scanf()函数有冲突?
题目:链表的建立

struct Addresslist *create()
{
struct Addresslist *head;
struct Addresslist *p;
struct Addresslist *tail;

char name[20];
head=NULL;
tail=NULL;

printf("输入第一个结点:\n");
printf("姓名:");
gets(name);

while(strcmp(name,"")!=0)
{
p=(struct Addresslist *)malloc(LEN);
if(p==NULL)
{
printf("内存不足!\n");
exit(1);
}
else
{
strcpy(p->name,name);
printf("输入分数:");
scanf("%s",p->score);
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
printf("输入下个个结点的数据:\n");
printf("姓名:");
gets(name);
}
}
if(head!=NULL)
tail->next=NULL;
printf("链表数据输入结束!\n");
return head;
}

程序跳过了红色那个gets(name)的语句,要是我把它改成scanf("%s",name)就可以读取scanf()这个语句,但是改了后是死
循环,红色的gets(name)不改,把scanf("%s",score)改成gets(score)循环一切就正常了?
搜索更多相关的解决方案: gets  scanf  函数  

----------------解决方案--------------------------------------------------------
  相关解决方案