home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06024b < prev    next >
Text File  |  1991-02-17  |  506b  |  32 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
  6.  
  7. main()
  8. {
  9.     char list[][7] = {
  10.         "red",
  11.         "blue",
  12.         "yellow",
  13.         "green"
  14.     };
  15.     int i, j;
  16.     char temp[7];
  17.  
  18.     for (i = NUMELEM(list) - 2; i >= 0; --i) {
  19.         for (j = 0; j <= i; ++j) {
  20.             if (strcmp(list[j], list[j + 1]) > 0) {
  21.                 strcpy(temp, list[j]);
  22.                 strcpy(list[j], list[j + 1]);
  23.                 strcpy(list[j + 1], temp);
  24.             }
  25.         }
  26.     }
  27.  
  28.     for (i = 0; i < NUMELEM(list); ++i)
  29.         printf("%s\n", list[i]);
  30. }
  31.  
  32.