write a programme to compare time stamp in c

 #include<stdio.h>

#include<string.h>


typedef struct time_stamp{

int year;

int month;

int date;

int hour;

int minute;

int seacond;

}time_stamp;


void display(time_stamp dt1,time_stamp dt2){

printf("the time stamp is: %d/%d/%d-%d:%d:%d\n",dt1.year,dt1.month,dt1.date,dt1.hour,dt1.minute,dt1.seacond);

//}

//void display(time_stamp dt2){

printf("the time stamp is: %d/%d/%d-%d:%d:%d\n",dt2.year,dt2.month,dt2.date,dt2.hour,dt2.minute,dt2.seacond);

}



int time_stampcmp(time_stamp dt1,time_stamp dt2){

if(dt1.hour>dt2.hour){

return 1;

}

if(dt1.hour<dt2.hour){

return -1;

}

if(dt1.minute>dt2.minute){

return 1;

}

if(dt1.minute<dt2.minute){

return -1;

}

if(dt1.seacond>dt2.seacond){

return 1;

}

if(dt1.seacond<dt2.seacond){

return -1;

}

    if(dt1.year>dt2.year){

return 1;

}

if(dt1.year<dt2.year){

return -1;

}

if(dt1.month>dt2.month){

return 1;

}

if(dt1.month<dt2.month){

return -1;

}

if(dt1.date>dt2.date){

return 1;

}

if(dt1.date<dt2.date){

return -1;

}

return 0;

}

int main(){

time_stamp dt1 = {2002,11,19,5,42,57};

time_stamp dt2 = {1995,10,30,4,21,36};

display(dt1,dt2);

int a = time_stampcmp (dt1,dt2);

printf("time stamp comparision function returns: %d",a);

return 0;

}



Comments

Popular posts from this blog

create a num table in a new file in c

write a struct programme to keep bank details in c