Operating System - HP-UX
1832950 Members
2763 Online
110048 Solutions
New Discussion

Re: Converting 2 times to epoch times

 
SOLVED
Go to solution
Henry Chua
Super Advisor

Converting 2 times to epoch times

Hi Guys,

I have written a program to convert a time to epoch time.
:

#include
#include
#include

int
main (argc,argv)
int argc;
char *argv[];
{
time_t rawtime;
struct tm * timeinfo;
int data[6], time_sec;
int i;

for(i=0; i<=6; i++)
data[i] = atoi(argv[i]);


time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = data[1] -1900;
timeinfo->tm_mon = data[2] - 1;
timeinfo->tm_mday = data[3];
timeinfo->tm_hour = data[4];
timeinfo->tm_min = data[5];
timeinfo->tm_sec = data[6];

time_sec =mktime ( timeinfo );

printf("%d", time_sec);

return 0;
}

But when i try to modify this to convert 2 times at once it fails and only convert the first. What should I do?

Regards
Henry
~
1 REPLY 1
Peter Nikitka
Honored Contributor
Solution

Re: Converting 2 times to epoch times

Hi,

please give us the commandline you use for the conversion of the two time specifications!

If you try pass 12 parameters to your program:
Your code runs statically over 6 of them regardless how much you offer:

for(i=0;i<=6;i++)
...

You could:
- check if params are passwd in tupels of six
- use an outer for-loop to group six params like

for(j=0;j<((argc-1)/6);j++)
...

- run your code as an inner for-loop

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"