我試圖通過按任意鍵在任何時候退出循環。我已經嘗試了下面的代碼,但它不能完成。需要你的幫助。先謝謝你。我正在使用C-Free 5.0。隨時退出循環
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int b=0, i;
int seconds;
printf("\nEnter number of seconds : ");
scanf("%d", &seconds);
while (b==0)
{
for(i=1;i<=seconds;i++)
{
time_t end = time(0) + 1;
while(time(0) < end)
;
seconds -= 1;
printf("Number of seconds left : %d\n", seconds);
b=kbhit();
}
if(seconds == 0)
{
exit(0);
}
}
printf("Number of remaining seconds left : %d\n", seconds);
}
什麼是「C-Free 5.0」?如果這是一個模糊的C編譯器,你可能更好地切換到gcc(如果你在Window上,則爲mingw)。 – ThiefMaster
http://stackoverflow.com/q/6731317/1273830可能的重複哦等你已經看到了這個問題?的kbhit? O_O – Prasanth