//定時器 #include <stdio.h> #include <time.h> #include <stdlib.h> int main(int num, char* arg[]){ //arg數組存放指針 //printf("個數:%d 參數值1:%s 參數值2:%s 參數值:%s\n",num,arg[0],arg[1],arg[2]); if(num!=2){ printf("必須輸入一個數字:%s\n",arg[0]); exit(1); } int duration = atoi(arg[1]); if(duration<=0) exit(1); //設置啟動時間 time_t start, current; time(&start); printf("開始時間:%s \n",ctime(&start)); do{ //設置當前時間 time(¤t); }while((current-start) != duration); printf("當前時間:%s \n",ctime(¤t)); return 0; }