Operating System - HP-UX
1834458 Members
2838 Online
110067 Solutions
New Discussion

Re: Calling the strftime() Function

 
Paul Murray
Occasional Contributor

Calling the strftime() Function

Dear Gurus,

I am currently trying to develop my C skills, but cannot work out how to do the following ....

I want to prefix all entries to a logfile with the current sysdate/time in the format of "[ddmmmyy:HHMM.ss]" - it appears that the strftime() function call will allow me to do this, but I have absolutely no idea on how to call it !!!

Can someone please show me the lines of code I would need to use.


(Sorry for being a C-learner !!)


Regards,
Paul.
My Brain Hurts !!!!!
2 REPLIES 2
Kenneth Platz
Esteemed Contributor

Re: Calling the strftime() Function

Try something like this:

#include

struct tm *t;
char buf[80];

t = localtime( time(NULL) );
strftime( buf, 80, "[%d%m%y:%H%M.%S]", t );

This is straight from the time(), localtime(), and strftime() man pages.

I hope this helps.
I think, therefore I am... I think!
Paul Murray
Occasional Contributor

Re: Calling the strftime() Function

Kenneth,

Many, many thanks for the assistance. Unfortunately, I am getting the following error ....


Error 212: "WriteLog.cpp", line 48 # Argument type 'tm *' does not match expected parameter type 'long *'


Thanks again,
Paul.
My Brain Hurts !!!!!