I need to create a struct where is set a date. I googled something and i found the tm structure
from the library time.h
, but I'm having some troubles; I need to print some dates on a log file, here an example:
typedef struct tm* tm_;
...
void NEW_Job()
{
time_t t;
tm_ secs;
t=time(NULL);
secs=localtime(&t);
add_QUEUEnode(generate_job());
fprintf(f, "\n%d:%d.%d : New job created.", secs->tm_hour, secs->tm_min, secs->tm_sec);
}
I really don't know where i'm wrong.
Thanks in advance for the help :)
The exact error wasn't there, but in another line of the code, exactly here:
void PCunload(int b)
{
time_t t;
tm_ secs;
int hh, mm, ss;
hh=(time(NULL)-n[b].start_time)/3600;
mm=((time(NULL)-n[b].start_time)%3600)/60;
ss=((time(NULL)-n[b].start_time)%3600)%60;
t=time(NULL);
secs=localtime(&t);
n[b].job.priority=-1;
-->>fprintf(f, "\n%d:%d.%d : PC number %d unloaded; elapsed time: %d:%d.%d", secs->tm_hour, secs->tm_min, secs->tm_sec, hh, mm, ss);
}
There I tried to do the conversion inside the printf functions, but something goes wrong... My apologies!
strftime() can help you printing date and time at your favorite format. Please take a look at man strftime.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.