以下程式示範使用 clock() 的結果
#include <stdio.h>
#include <time.h>
int main(void)
{
long fiveseconds = CLOCKS_PER_SEC * 5;
printf("程式開始執行,準備暫停五秒...\n");
while (clock() < fiveseconds) {
}
printf("五秒過後,程式執行結束...\n");
return 0;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:cclock.c
功能:示範 time.h 中函數 clcok() 的使用
作者:張凱慶
時間:西元2010年6月 */編譯後執行,結果如下

您可以繼續參考
時間 time.h
- clock_t clock(void);
- time_t time(time_t* timer);
- double difftime(time_t timer2, time_t timer1);
- time_t mktime(struct tm* ptm);
- struct tm* localtime(const time_t* timer);
- char *(const struct tm* tmptr);
- char* ctime(const time_t* timer);
- size t strftime(char* s, size t n, const char* format, const struct tm* tptr);
沒有留言:
張貼留言