date comparison
#include<stdio.h>
typedef struct timestamp{
int date,month,year,hours,minutes,seconds;
}time;
int display(time d );
int timecmp(time d1, time d2);
int main()
{
time d1={11,3,2004,3,45,56};
time d2={11,3,2004,3,30,44};
display(d1);
display(d2);
int a=timecmp(d1,d2);
printf("dater comparison returns %d",a);
}
int display(time d )
{
printf("%d/%d/%d/%d:%d:%d\n",d.date,d.month,d.year,d.hours,d.minutes,d.seconds);
}
int timecmp(time d1, time d2)
{
if(d1.date>d2.date)
{
return 1;
}
if(d1.date<d2.date)
{
return -1;
}
if(d1.month>d2.month)
{
return 1;
}
if(d1.month<d2.month)
{
return -1;
}
if(d1.year>d2.year)
{
return 1;
}
if(d1.year<d2.year)
{
return -1;
}
if(d1.hours>d2.hours)
{
return 1;
}
if(d1.hours<d2.hours)
{
return 1;
}
if(d1.minutes>d2.minutes)
{
return 1;
}
if(d1.minutes<d2.minutes)
{
return -1;
}
if(d1.seconds>d2.seconds)
{
return 1;
}
if(d1.seconds<d2.seconds)
{
return -1;
}
else
{
return 0;
}
}
Comments
Post a Comment