例如,如果我做了一個簡單的開關箱,我將如何根據輸入使控制檯應用程序關閉?我不想用break來使用;並跳過循環,我想完全關閉控制檯。如何使用開關盒在C中退出控制檯應用程序?
char choice;
printf("Run random function \n");
printf("Exit \n");
choice = getchar();
fflush(stdin);
switch(choice)
{
case '1':
//randomFunction();
case '2':
//I want this case to exit the console the console
}
**出口(0); **會是你的選擇。 – Gangadhar
'fflush(stdin);'是依賴於執行的 –
@GrijeshChauhan更糟糕的是:這是未定義的行爲!例如見[這裏](http://stackoverflow.com/questions/2979209/using-fflushstdin) –