📄 cmp_longtime.c
字号:
/*===========================================================================*//* DMC Interim | cmp_longtime | utility *//*===========================================================================*//* Name: cmp_longtime Purpose: compare two times in struct input_time format Usage: int cmp_longtime (); struct input_time time1; struct input_time time2; int result; result = cmp_longtime (time1, time2); Input: time1 = 1st time in struct input_time format time2 = 2nd time in struct input_time format Output: result = 0 if time1 == time2 (to e-04 sec) = -1 if time1 < time2 = 1 if time1 > time2 Externals: none Warnings: none Errors: none Called by: anything Calls to: none Algorithm: check each element of the time structure; if an inequality is found, return the appropriate value. If no inequalities are found, times are equal. Notes: The time structure looks like: struct input_time { unsigned short int year; unsigned short int day; char hour; char minute; char second; unsigned short int fracsec; }; Problems: None known Debug: level D_MAX - level D_MAX - level D_MAX - print out start, comparison and finish notices References: none Language: ANSI standard C Author: Kevin MacKenzie 01 mar 1989 Revisions:*/#include "output.h"int cmp_longtime (time1, time2)struct input_time time1; /* first time to compare */struct input_time time2; /* second time to compare */{ int err = 0; /* result */ if (Debug > D_MAX) fprintf (D_OUT, "[cmp_longtime] Started.\n"); /* check year */ if (time1.year != time2.year) err = (time1.year < time2.year) ? -1 : 1; /* check day */ if (!err && time1.day != time2.day) err = (time1.day < time2.day) ? -1 : 1; /* check hour */ if (!err && time1.hour != time2.hour) err = (time1.hour < time2.hour) ? -1 : 1; /* check minute */ if (!err && time1.minute != time2.minute) err = (time1.minute < time2.minute) ? -1 : 1; /* check second */ if (!err && time1.second != time2.second) err = (time1.second < time2.second) ? -1 : 1; /* check fractional second */ if (!err && time1.fracsec != time2.fracsec) err = (time1.fracsec < time2.fracsec) ? -1 : 1; if (Debug > D_MAX) { print_time( "[cmp_longtime] time1: ", &time1 ); print_time( "[cmp_longtime] time2: ", &time2 ); if (err == 1) fprintf (D_OUT, "[cmp_longtime] time1 > time2\n"); else if (err == 0) fprintf (D_OUT, "[cmp_longtime] time1 = time2\n"); else if (err == -1) fprintf (D_OUT, "[cmp_longtime] time1 < time2\n"); } if (Debug > D_MAX) fprintf (D_OUT, "[cmp_longtime] Finished.\n"); return (err);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -