为什么编译没有报错,但一运行就错误。。


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct time
{
 int hour;
 int minute;
 int second;
};
struct time TimeUpdate(struct time now);
int main(int argc,char const argv[])
{
 int i;
 struct time testtimes[5]={{23,59,59},{12,52,36},{06,12,58},{00,00,00},{25,01,26}};
 for(i=0;i<5;i++)
 {
 printf("Time is %02d:%02d:%02d\n",testtimes[i].hour ,testtimes[i].minute ,testtimes[i].second );
 testtimes[i]=TimeUpdate(testtimes[i]);
 printf("...one second after the now time is %02d:%02d:%02d\n",testtimes[i].hour ,testtimes[i].minute ,testtimes[i].second);
 getchar();
 }

 return 0;
}
struct time TimeUpdate(struct time now)
{
 if(now.hour>=0&&now.hour<24)
 {
  if(now.second>=60)
  {
   now.minute=now.minute +now.second /60;
   now.second=now.second-60*(now.second/60);
  
      if(now.minute>=60)
     {
     now.hour=now.hour+now.minute/60;
     now.minute=now.minute-60*(now.minute/60);
     }
  }
  printf("您输入的标准时间格式是 %02d:%02d:%02d\n",now.hour,now.minute ,now.second );
  ++now.second;
  if(now.second ==60)
  {
   now.second=0;
   ++now.minute;
   if(now.minute==60)
   {
    now.minute=0;
    ++now.hour;
    if(now.hour==24)
    {
     now.hour =0;
    }
   }
  }

   
 }
 else
 {
  printf("时间输入有误!\n");
 }
}

番茄的卍番茄酱
浏览 1477回答 2
2回答

阿旭_

错误的提示是什么?我试着运行了一下,可以运行,结果如下:

番茄的卍番茄酱

添加一个retern now;
打开App,查看更多内容
随时随地看视频慕课网APP