#include "stdio.h"
struct date
{
int month;
int day;
int year;
};
struct time
{
int hour;
int minute;
int seconds;
};
struct dateAndTime
{
struct date sdate;
struct time stime;
};
main()
{
struct dateAndTime ClockKeeper(struct dateAndTime numberDate);
struct dateAndTime numberNow, turnNow;
printf("Enter time and date is:(hh:mm:ss mm/dd/yy)");
scanf("%d:%d:%d %d/%d/%d",&numberNow.stime.hour,&numberNow.stime.minute,&numberNow.stime.seconds,
&numberNow.sdate.month,&numberNow.sdate.day,&numberNow.sdate.year);
turnNow = ClockKeeper(numberNow);
printf("Right now time and date : %.2d:%.2d:%.2d %d/%d/%.2d\n",turnNow.stime.hour,
turnNow.stime.minute,turnNow.stime.seconds,turnNow.sdate.month,turnNow.sdate.day,
turnNow.sdate.year % 100);
}
struct dateAndTime ClockKeeper (struct dateAndTime numberDate)
{
struct dateAndTime dateUpdate(struct dateAndTime n);
++numberDate.stime.seconds;
if(numberDate.stime.seconds == 60){
numberDate.stime.seconds = 0;
++numberDate.stime.minute;
if(numberDate.stime.minute == 60){
numberDate.stime.minute = 0;
++numberDate.stime.hour;
if(numberDate.stime.hour == 24){
numberDate.stime.hour = 0;
struct dateAndTime dateUpdate(struct dateAndTime numberDate);
}
}
}
return numberDate;
}
struct dateAndTime dateUpdate(struct dateAndTime n)
{
const int dayperMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(n.sdate.day == dayperMonth[n.sdate.month - 1]){
n.sdate.day = 0;
n.sdate.month++;
if(n.sdate.month == 12){
n.sdate.month = 0;
n.sdate.year++;
}
}
return n;
}