home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_06 / 3n06052a < prev    next >
Text File  |  1992-02-03  |  544b  |  35 lines

  1.  
  2. Listing 1
  3.  
  4. #include <stdio.h>
  5.  
  6. typedef int T;
  7.  
  8. /*
  9.  * Tcmp - compare two arrays of integers
  10.  */
  11. int Tcmp(const T *a1, const T *a2, size_t n)
  12.     {
  13.     int cmp;
  14.     size_t i;
  15.  
  16.     for (i = 0; i < n; ++i)
  17.         if ((cmp = a1[i] - a2[i]) != 0)
  18.             return cmp;
  19.     return 0;
  20.     }
  21.  
  22. /*
  23.  * Sample calls to Tcmp...
  24.  */
  25. int a[] = {1, 2, 3, 4, -5};
  26. int b[] = {1, 2, 3, 4, 4};
  27.  
  28. int main(void)
  29.     {
  30.     printf("a vs. b = %d\n", Tcmp(a, b, 4));
  31.     printf("a vs. b = %d\n", Tcmp(a, b, 5));
  32.     return 0;
  33.     }
  34.  
  35.