S
sugaray
hi, below is my program for doing exercise with library time functions,
something is not right with it, and for the time being i couldn't figure
out what's wrong and where, thanx for your help.
#include <time.h>
#include <stdio.h>
double TimeDifference(struct tm *t1,struct tm *t2)
{
return difftime(mktime(t1),mktime(t2));
}
char *ConstructTime(struct tm *time,int month,int day,int year)
{
time->tm_mon=month-1;
time->tm_mday=day;
time->tm_year=year-1900;
mktime(time);
return asctime(time);
}
int main(int argc,char **argv)
{
struct tm now,t1,t2;
char *tmstr;
double diff;
int month,day,year;
scanf("%d%d%d",&month,&day,&year);
tmstr=ConstructTime(&now,month,day,year);
printf("%s",tmstr);
ConstructTime(&t1,6,7,2004);
ConstructTime(&t2,6,9,2004);
diff=TimeDifference(&t1,&t2);
printf("%f\n",diff);
return 0;
}
something is not right with it, and for the time being i couldn't figure
out what's wrong and where, thanx for your help.
#include <time.h>
#include <stdio.h>
double TimeDifference(struct tm *t1,struct tm *t2)
{
return difftime(mktime(t1),mktime(t2));
}
char *ConstructTime(struct tm *time,int month,int day,int year)
{
time->tm_mon=month-1;
time->tm_mday=day;
time->tm_year=year-1900;
mktime(time);
return asctime(time);
}
int main(int argc,char **argv)
{
struct tm now,t1,t2;
char *tmstr;
double diff;
int month,day,year;
scanf("%d%d%d",&month,&day,&year);
tmstr=ConstructTime(&now,month,day,year);
printf("%s",tmstr);
ConstructTime(&t1,6,7,2004);
ConstructTime(&t2,6,9,2004);
diff=TimeDifference(&t1,&t2);
printf("%f\n",diff);
return 0;
}