The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A program to trace execution of another program jiten_hegde High Level Programming 3 08-19-2008 05:26 AM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 05:21 PM
Which Base Level Filesets needed by a specific program? cypher82 UNIX for Advanced & Expert Users 4 05-29-2008 08:07 AM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 01:44 PM
Wierd C program. Help Needed karthikb23 High Level Programming 16 11-16-2007 02:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2007
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
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
  #2 (permalink)  
Old 11-19-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
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);
}
  #3 (permalink)  
Old 11-19-2007
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
Hi fpmurphy,

It works thanks a lot for the help.

Cheers
dwgi32
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0