任何人都可以請解釋爲什麼我的while循環不會結束,當我輸入字符'Q'?它不停地循環,即使我我的布爾值設置爲false,當用戶輸入「Q」,它假設scanf函數爲char input
後結束。雖然循環在C
我的代碼:
#include <stdio.h>
typedef int bool;
#define true 1
#define false 0
int main(void) {
char input;
char output;
bool tf = true;
printf("Welcome to the Coder!\n");
while (tf) {
printf("Choose Input (H,A,B,Q) : ");
scanf_s(" %c\n", &input);
if (input == 'Q') {
tf = false;
}
else {
printf("Choose Output (H,A,B) : ");
scanf_s(" %c\n", &output);
}
}
return 0;
}
您是否在輸入Q後按下輸入? – immibis
又一個scanf問題? –
是的,我確實按下輸入 – Impalerz