Tuesday, August 28, 2007

C program for update time by 1 sec

/*pgr to update time by 1 sec
written by sekhar
written on 08/08/07
modified on 08/08/07 */
#include stdio.h
typedef struct
{
int sec;
int min;
int hours;
} time_t;
void update_time(time_t *,time_t *);
main()
{
time_t present,updated;
puts("enter the present time in hh:mm:ss");
scanf("%d%d%d",&present.hours,&present.min,&present.sec);
printf("%d:%d:%d",present.hours,present.min,present.sec);
while(1)
{
update_time(&present,&updated);
printf("\n%d:%d:%d",updated.hours,updated.min,updated.sec);
present=updated;
if(present.hours==13)
exit();
}
}
// function description
void update_time(time_t *time1,time_t *time2)
{
if(time1->sec!=59)
{
time2->sec=time1->sec+1;
time2->min=time1->min;
time2->hours=time1->hours;
}
else
{
if(time1->min!=59)
{ time2->sec=0;
time2->min=time1->min+1;
time2->hours=time1->hours;
}
else
{
time2->sec=0;
time2->min=0;
time2->hours=time1->hours+1;
}
}
}