#include <stdio.h> #include <stdlib.h> #include <signal.h> #define N 10 void sig_int(int sig) { printf("/tOh,man!/033[0m/n"); exit(0); } int main() { int h=1,m=1,s=N-2; signal(SIGINT,&sig_int); printf("Don't bother me,I am counting down./n" "I only recongnize: ctrl+c/n"); while(1){ printf("/r/033[1;31m%02d:%02d:%02d",h,m,s); fflush(stdout); if(h+m+s<=0) break; //死循环退出点 usleep(100000); //0.1秒一次数据更新 if(s==0){ s=N; if (m>0) m--; else h--,m=N-1; } s--; } printf("/nhmm,Good patience!/033[0m/n"); return 0; }