刚学C,求帮忙看个程序,看看哪里错了为什么运行错误/*计算下一秒时间*/
/*计算下一秒时间*/#include<stdio.h>
#include<stdlib.h>
struct time{
int hour;
int minute;
int second;
};
struct time readTime();
struct time nextTime(struct time t);
int main()
{
struct time nowTime,next_time;
nowTime = readTime();
next_time = nextTime(nowTime);
printf("nowTime = %d:%d:%d\n",nowTime.hour,nowTime.minute,nowTime.second);
printf("next_time = %d:%d:%d\n",next_time.hour,next_time.minute,next_time.second);
system("PAUSE");
return 0;
}
struct time readTime()
{
struct time t;
int error;
do{
error = 0;
scanf("%d:%d:%d",t.hour,t.minute,t.second);
if(t.hour<0||t.hour>23)
{
printf("小时数据错误:0~23!\n");
error = 1;
}
if(t.minute<0||t.minute>59)
{
printf("分钟数据错误:0~59!\n");
error = 1;
}
if(t.second<0||t.second>59)
{
printf("秒钟数据错误:0~59!\n");
error = 1;
}
if(error)
printf("重新输入!\n");
}while(error);
return t;
}
struct time nextTime(struct time t)
{
t.second++;
if(t.second>59)
{
t.second = 0;
t.minute++;
if(t.minute>59)
{
t.minute = 0;
t.hour++;
if(t.hour>23)
t.hour = 0;
}
}
return t;