The UNIX and Linux Forums  

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
System time comparison to fixed defined time zainravi Shell Programming and Scripting 2 03-22-2009 01:13 PM
Convert Epoch Time to Standard Date and Time & Vice Versa DrivesMeCrazy Shell Programming and Scripting 5 02-07-2009 01:40 AM
Need to get 4 Hrs back time and compare with successive time maanik85 UNIX for Dummies Questions & Answers 2 07-15-2008 09:48 AM
Linux Going Big Time and Prime Time Against Windows, UNIX (WSJ) (Addict 3D) iBot UNIX and Linux RSS News 0 06-21-2007 05:10 PM
How To Provide Time Sync Using Nts-150 Time Server On Unix Network? pesty UNIX for Advanced & Expert Users 2 03-22-2007 02:20 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-28-2009
Kattoor Kattoor is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 25
How to log time in C/C++

Hi,

Actually I want to create a log file in c, which should log the details in to log file.
Here am facing one problem..like if I am doing loging am not able to log the exact time..Its printing the same time..Can anybody help me out on this..??

Sample code:
===========
#include <stdio.h>
#include <time.h>
#include<stdlib.h>
struct tm *ptr;
time_t lt;

FILE * pFile = fopen("myfile.txt","a");
int main ()
{
int n;
char name [100];
lt = time(NULL);

fprintf(pFile,"\n==========starting===========\n");
for (n=0 ; n<2 ; n++)
{
puts ("please, enter a name: ");
gets (name);
printf("%s %d",__FILE__,__LINE__);
fprintf (pFile,"\nName %d [%-10.10s] : %s : Line %d: %s\n",n,name,__FILE__,__LINE__,asctime(localtime(&lt)));
}
fprintf(pFile,"Hello : %s : Line %d: %s\n",__FILE__,__LINE__,asctime(localtime(&lt)));
fprintf(pFile,"Error : %s : Line %d: %s\n",__FILE__,__LINE__,asctime(localtime(&lt)));

fprintf(pFile,"=======COMPLETED========");
return 0;
}

Here I could print the log time..but always its same..I need it in a sequence order..
Could you please help me out on this..?

Thanks in advance..!
 

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 05:18 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