为什么要贴出这段代码,因为这段代码很有代表性,对刚入门的同学有点启发。
- /* time */
-
typedef struct Time {
-
uint8_t hour;
-
uint8_t min;
-
uint8_t sec;
-
uint8_t hundredths;
-
} TIME_t;
-
-
-
/* if the time1 is the same as time2, return is 0
-
if time1 is after time2, returns positive
-
if time1 is before time2, returns negative
-
*/
-
int CompareTime(TIME_t &time1, TIME_t &time2)
-
{
-
int diff = 0;
-
-
diff = (int) time1.hour - (int) time2.hour;
-
if (diff == 0)
-
{
-
diff = (int) time1.min - (int) time2.min;
-
if (diff == 0)
-
{
-
diff = (int) time1.sec - (int) time2.sec;
-
if (diff == 0)
-
{
-
diff = (int) time1.hundredths - (int) time2.hundredths;
-
}
-
}
-
}
-
-
return diff;
-
}
阅读(1137) | 评论(0) | 转发(0) |