void getInputData(void) {
char c = 0;
while (c != 'x') {
printf("Enter a letter:");
fflush(stdout);
c = getchar();
printf("You entered: %c \n",c);
fflush(stdout);
getchar();
}
printf("\nYou entered x and the loop exited\n");
}
爲什麼getchar()
在這個功能最後需要?我不明白爲什麼它在那裏。爲什麼在這個函數中必須使用getchar()?我不明白爲什麼它在那裏
你試過沒有第二個getchar()會發生什麼嗎? –
它是在'getchar'之後收集'newline'仍然在輸入緩衝區中,但是有更好的方法來實現它。 –
也許讀取一個換行符,因爲除非按下ENTER鍵,否則第一個getchar()將不會返回? –