
C语言简单问题,在线等,急用加分
Student*Delete_a_Record(Student*head){Charname[100][20];charfoobar,alter;inti;printf(...
Student *Delete_a_Record(Student *head)
{ Char name[100][20];
char foobar,alter;
int i;
printf("Delete a record?...Y/N\n");
scanf("%c",&foobar);
c3: if(foobar=='y'||foobar=='Y')
{ printf("Please enter name list\n");
for(i=0;;i++)
{ gets(name[i]);
Delete(head,name[i]);
else if(foobar=='n'||foobar=='N')
{ printf("Delete teminated\n"); goto End; }
else goto c3;
End: return head;
}
我写了这样一个函数,经证明,中间调用的delete函数没有问题。
问题在于:在c3处,输入foobar之后,系统显示 please input namelist,但是在这里没有停留,直接显示Continue?...Y/N 。在当我再次用Y确认后恢复正常,其中又一次录入肯定是不对的,求高人解答,致谢。
c3: foobar=getchar();
if(foobar=='y'||foobar=='Y')
{ printf("please input namelist\n");
for(i=0;;i++)
{ gets(name[i]);
printf("Continue?...Y/N\n");
c4: alter=getchar(); getchar();
if(alter=='y'||alter=='Y') continue;
else if(alter=='n'||alter=='N') break;
else goto c4; }
}不好意思,上面的程序少了一部分 展开
{ Char name[100][20];
char foobar,alter;
int i;
printf("Delete a record?...Y/N\n");
scanf("%c",&foobar);
c3: if(foobar=='y'||foobar=='Y')
{ printf("Please enter name list\n");
for(i=0;;i++)
{ gets(name[i]);
Delete(head,name[i]);
else if(foobar=='n'||foobar=='N')
{ printf("Delete teminated\n"); goto End; }
else goto c3;
End: return head;
}
我写了这样一个函数,经证明,中间调用的delete函数没有问题。
问题在于:在c3处,输入foobar之后,系统显示 please input namelist,但是在这里没有停留,直接显示Continue?...Y/N 。在当我再次用Y确认后恢复正常,其中又一次录入肯定是不对的,求高人解答,致谢。
c3: foobar=getchar();
if(foobar=='y'||foobar=='Y')
{ printf("please input namelist\n");
for(i=0;;i++)
{ gets(name[i]);
printf("Continue?...Y/N\n");
c4: alter=getchar(); getchar();
if(alter=='y'||alter=='Y') continue;
else if(alter=='n'||alter=='N') break;
else goto c4; }
}不好意思,上面的程序少了一部分 展开
1个回答
展开全部
scanf("%c",&foobar); 后加 fflush(stdin); 清除缓冲区里的enter 键。
foobar=getchar(); 后加 fflush(stdin); 清除缓冲区里的enter 键。
foobar=getchar(); 后加 fflush(stdin); 清除缓冲区里的enter 键。
追问
那么头文件需要追加什么吗?
追答
stdio.h stdlib.h
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询