我想要求用戶輸入,並且我需要這樣做,以便如果用戶鍵入exit
,它會終止程序。來自輸入的比較字符串
這裏是我的,但它不工作由於某些原因:
int main(void) {
char input[100];
printf("Enter: ");
while(fgets(input, 100, stdin)) {
if(strcmp("exit", input) == 0) {
exit(0);
}
}
}
爲什麼不退出?
謝謝合作。另外,如果輸入值之間需要逗號(例如,輸入可能是'test,15'),我將如何分離這些值並將它們放入其他變量中? – user2805199