Help needed regarding c program

Hi,

Currently, i have an application that does logging of messages into a text file and i record the timing for the messages in a [hh:mm:ss] format. However, i need to log the messages up to millisec level and the struct tm i am using now only support up to sec, is there any other way to get millisec?

Cheers

You can use the gettimeofday() and the timeval structure to achieve what you want.

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

int
main(void)
{
char buf[30];
struct timeval tv;
time_t ct;
int ms;

gettimeofday\(&tv, NULL\);
ct = tv.tv_sec;
strftime\(buf, 30, "%m/%d/%y %T.", localtime\(&ct\)\);
ms = \(tv.tv_usec % 1000000\) / 1000;

printf\("Timestamp: %s%d\\n", buf, ms\);

}

Hi fpmurphy,

It works thanks a lot for the help.

Cheers
dwgi32