【发布时间】:2013-09-02 12:47:40
【问题描述】:
在下面的一段代码中,while 循环在做什么(标有“循环”)?:-
int main(void)
{
char code;
for (;;)
{
printf("Enter operation code: ");
scanf(" %c", &code);
while (getchar() != '\n') // loop
;
switch (code)
{
case 'i':
insert();
break;
case 's':
search();
break;
case 'u':
update();
break;
case 'p':
print();
break;
case 'q':
return 0;
default:
printf("Illegal code\n");
}
printf("\n");
}
}
声明:代码不完整,只是代码的一部分,无法编译。
【问题讨论】:
-
它在反复调用
getchar()...你认为它做了什么? -
查看stackoverflow.com/a/13710915/613130 以了解
scanf的一些技巧 -
@xanatos 感谢您的链接。