コード 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()
この場合の機能の違いは何ですか?