--> Christopher Butler wrote to All <--
CB>If I've got two variables, stored as arrays of 3 bytes:
CB>
CB>typedef byte DateType[3];
CB>
CB>How do I test whether one is greater than the other?
Assuming the bytes are in order [0] being the most significant, and
each byte represents a number:
int DTcmp(const DateType *a, const DateType *b)
{
/* Returns:
* 1 if *a > *b
* 0 if *a == *b
* -1 if *a < *b
*/
int i;
char *x = (char *) a;
char *y = (char *) b;
for(i = 0; i < sizeof(DateType); i++, x++, y++)
{
if(*x > *y) return 1;
if(*x < *y) return -1;
}
return 0;
}
PS: Why isn't this a class instead of a type?
X CMPQwk 1.42 1692 X"In headaches and in worry Vaguely life leaks away." -
W.H. Auden
--- Maximus/2 3.01
---------------
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
|