代码 1:-
char ch1, ch2;
printf("Input the first character:");
scanf("%c", &ch1);
while(getchar()!='\n');
printf("Input the second character:");
ch2 = getchar();
在这种情况下while(getchar()!='\n');,清除enter-key第一次输入时按下的效果。
代码 2:-
char ch1, ch2;
printf("Input the first character:");
scanf("%c", &ch1);
while(getch()!='\n');
printf("Input the second character:");
ch2 = getchar();
在这种情况下while(getch()!='\n');,不要清除enter-key第一次输入时按下的效果。循环结果是无限的。
getch()和getchar()这个案例的功能有什么区别?