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 >
Text File  |  1992-02-03  |  1KB  |  52 lines

  1.  
  2. Listing 3
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #include "arraycmp.h"
  8.  
  9. /*
  10.  * Some element comparison functions
  11.  */
  12. #define intcf(i, j) ((i) - (j))
  13. arraycmp_implement(int);
  14.  
  15. inline int doublecf(double d, double e)
  16.     {
  17.     return d < e ? -1 : d == e ? 0 : 1;
  18.     }
  19. arraycmp_implement(double);
  20.  
  21. typedef const char *str;
  22. #define strcf(s, t) strcmp((s), (t))
  23. arraycmp_implement(str);
  24.  
  25. /*
  26.  * Sample calls to arraycmp...
  27.  */
  28. #define DIM(a) (sizeof(a) / sizeof(a[0]))
  29.  
  30. int a[] = {1, 2, 3, 4, -5};
  31. int b[] = {1, 2, 3, 4, 4};
  32.  
  33. double f[] = {1, 2, 3, 4, 5};
  34. double g[] = {1, 2, 3, 3, 4};
  35.  
  36. char *s[] = {"123", "456", "789"};
  37. char *t[] = {"123", "789", "456"};
  38.  
  39. int main(void)
  40.     {
  41.     printf("a vs. b = %d\n",
  42.         arraycmp(a, b, DIM(a) - 1));
  43.     printf("a vs. b = %d\n",
  44.         arraycmp(a, b, DIM(a)));
  45.     printf("f vs. g = %d\n",
  46.         arraycmp(f, g, DIM(f)));
  47.     printf("s vs. t = %d\n",
  48.         arraycmp(s, t, DIM(s)));
  49.     return 0;
  50.     }
  51.  
  52.