/输入时间,输出下一秒的时间/
#include <stdio.h>
struct time_rec
{
int hours ;
int mins ;
int secs ;
}time;
void input_time(struct time_rec *current_time)
{
printf("请输入当前时间(时 分 秒):");
scanf("%d%d%d",¤t_time->hours,¤t_time->mins,¤t_time->secs);
}
void increment_time(struct time_rec *current_time)
{
if(current_time->secs==59)
{
if(current_time->mins==59)
{
if(current_time->hours==23)
{
current_time->hours = 0;
current_time->mins = 0;
current_time->secs = 0;
}
else
{
current_time->hours+=1;
current_time->mins = 0;
current_time->secs = 0;
}
}
else
{
current_time->mins+=1;
current_time->secs = 0;
}
}
else
{
current_time->secs+=1;
}
}
void output_time(struct time_rec *current_time)
{
printf("%d时%d分%d秒!",current_time->hours,current_time->mins,current_time->secs);
}
int main()
{
int i;
struct time_rec *p = &time;
input_time(p);
increment_time(p);
output_time(p);
return 0;
}