[問題] 關於撰寫計時器的程式
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
想請問以下的程式碼:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct tm *ptrnow;
int i;
time_t loc_now, std_now;
time(&std_now);
i=0;
while(1){
time(&loc_now);
if(loc_now-std_now == i){
system("cls");
ptrnow = localtime(&loc_now);
printf("%s", asctime(ptrnow));
i++;
}
}
system("PAUSE");
return 0;
}
之後跑出的結果會是:
Sat Sep 10 11:01:06 2011
07
08
.....
之後按照秒數一直跑.....
書上是說,利用time()可得到從標準時(格林威治時間)1970/1/1 00:00:00起所經過的秒數
那我想問的是,既然time()函數的參數是loc_now與std_now.
那為何在if的條件式中loc_now-std_now == i,loc_now-std_now會先差0,接著差1,再接著
差2,此條件式想表達的究竟是什麼? 謝謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.124.116
推
09/10 11:23, , 1F
09/10 11:23, 1F
→
09/10 11:25, , 2F
09/10 11:25, 2F
→
09/10 11:25, , 3F
09/10 11:25, 3F
→
09/10 12:30, , 4F
09/10 12:30, 4F
→
09/10 12:31, , 5F
09/10 12:31, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章