compare date,year, month, hour, minute, second

 #include<stdio.h>

#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct date {
  int year;
  int mounth;
  int date;
  int hours;
  int min;
  int sec;

}d;
int comp(d c,d c2){
 if(c.year<c2.year){
   return -1;
 }
 if(c.year>c2.year){
   return 1;
 }

 if(c.mounth<c2.mounth){
  return -1;
 }
 if(c.mounth>c2.mounth){
  return 1;
 }
  if(c.date<c2.date){
  return -1;
 }
  if(c.date>c2.date){
  return 1;
 }
  if(c.hours<c2.hours){
  return -1;
 }
  if(c.hours>c2.hours){
  return 1;
 }
  if(c.min<c2.min){
  return -1;
 }
  if(c.min>c2.min){
  return 1;
 }
  if(c.sec<c2.sec){
  return -1;
 }
  if(c.sec>c2.sec){
  return 1;
 }


 return 0;
}
int main(){
  d c={20,7,21,6,25,11};
  d c2= {2,7,21,6,25,11};
  int a = comp(c,c2);

system ("cls");
 printf("%d\n",a);
  getch();
  return 0;
}

Comments

Popular posts from this blog

Snake game.c

Type declaration

Array with function