302班

java突击队
posts - 151, comments - 74, trackbacks - 0, articles - 14
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

time的更新、设置

Posted on 2007-07-02 19:50 停留的风 阅读(244) 评论(0)  编辑  收藏 所属分类: C语言学习历程

#include<stdio.h>

struct time
{
  int hour;
  int minutes;
  int seconds;
};

int main(void)
{
  struct time timeUpdate(struct time now);
  struct time currentTime,nextTime;

  printf("Enter the time (hh:mm:ss).\n");
  scanf("%i:%i:%i",&currentTime.hour,&currentTime.minutes,&currentTime.seconds);

  nextTime=timeUpdate(currentTime);
  printf("Updated time is %.2i:%.2i:%.2i\n",nextTime.hour,nextTime.minutes,nextTime.seconds);

  return 0;
}

struct time timeUpdate(struct time now)
{
  ++now.seconds;
  if(now.seconds==60)
  {
    now.seconds=0;
 ++now.minutes;
 if(now.minutes==60)
 {
   now.minutes=0;
   ++now.hour;
   if(now.hour=24)
    now.hour=0;
 }
  }
  return now;
}

测试结果:


只有注册用户登录后才能发表评论。


网站导航: