知識社群登入
這個程式,證明微軟的 MSDN 的範例錯誤
by 高顯忠, 2010-11-18 16:48, 人氣(1686)
#if 0

The time is Thu Nov 18 16:43:19.296 2010
ms= 296
 Press [Esc] for stop! other key for continue...



The time is Thu Nov 18 16:43:20.46 2010
ms= 046
 Press [Esc] for stop! other key for continue...

 上面,當 ms= 46的時候,必須印出來是 20.046,
 卻發生錯誤,印成 20.46, 就是 20.460,
 很明顯的,是一個 錯誤。

微軟的 MSDN, 關於 ftime() 的範例程式,寫錯了。

#endif
// ----------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>

#include <sys/timeb.h>
#include <time.h>

#include "sj-01.h"
// ----------------------------------------------

int main()
{
struct _timeb timebuffer;
char *timeline;
int ms;
for (;;) {
skip(3);
_ftime( &timebuffer );
ms= timebuffer.millitm;
timeline = ctime( & ( timebuffer.time ) );
printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
printf("ms= %03d\n", ms);
pause();
}
return 0;
}// end of main()