home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_03_06
/
3n06056a
< prev
next >
Wrap
Text File
|
1992-02-03
|
1KB
|
52 lines
Listing 3
#include <stdio.h>
#include <string.h>
#include "arraycmp.h"
/*
* Some element comparison functions
*/
#define intcf(i, j) ((i) - (j))
arraycmp_implement(int);
inline int doublecf(double d, double e)
{
return d < e ? -1 : d == e ? 0 : 1;
}
arraycmp_implement(double);
typedef const char *str;
#define strcf(s, t) strcmp((s), (t))
arraycmp_implement(str);
/*
* Sample calls to arraycmp...
*/
#define DIM(a) (sizeof(a) / sizeof(a[0]))
int a[] = {1, 2, 3, 4, -5};
int b[] = {1, 2, 3, 4, 4};
double f[] = {1, 2, 3, 4, 5};
double g[] = {1, 2, 3, 3, 4};
char *s[] = {"123", "456", "789"};
char *t[] = {"123", "789", "456"};
int main(void)
{
printf("a vs. b = %d\n",
arraycmp(a, b, DIM(a) - 1));
printf("a vs. b = %d\n",
arraycmp(a, b, DIM(a)));
printf("f vs. g = %d\n",
arraycmp(f, g, DIM(f)));
printf("s vs. t = %d\n",
arraycmp(s, t, DIM(s)));
return 0;
}