Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1036809
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类: C/C++

2011-05-25 22:23:07

为什么要贴出这段代码,因为这段代码很有代表性,对刚入门的同学有点启发。

  1. /* time */
  2. typedef struct Time {
  3.     uint8_t hour;
  4.     uint8_t min;
  5.     uint8_t sec;
  6.     uint8_t hundredths;
  7. } TIME_t;


  8. /* if the time1 is the same as time2, return is 0
  9.    if time1 is after time2, returns positive
  10.    if time1 is before time2, returns negative
  11. */
  12. int CompareTime(TIME_t &time1, TIME_t &time2)
  13. {
  14.     int diff = 0;

  15.     diff = (int) time1.hour - (int) time2.hour;
  16.     if (diff == 0)
  17.     {
  18.         diff = (int) time1.min - (int) time2.min;
  19.         if (diff == 0)
  20.         {
  21.             diff = (int) time1.sec - (int) time2.sec;
  22.             if (diff == 0)
  23.             {
  24.                 diff = (int) time1.hundredths - (int) time2.hundredths;
  25.             }
  26.         }
  27.     }
  28.   
  29.     return diff;
  30. }





阅读(1076) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~