home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d110 / pdc.lha / Pdc / lib / strcmp.c < prev    next >
Text File  |  1987-10-28  |  891b  |  34 lines

  1. /*
  2.  * strcmp - compare string s1 to s2
  3.  */
  4.  
  5. int                                    /* <0 for <, 0 for ==, >0 for > */
  6. strcmp(s1, s2)
  7. CONST char *s1;
  8. CONST char *s2;
  9. {
  10.          register CONST char *scan1;
  11.          register CONST char *scan2;
  12.  
  13.          scan1 = s1;
  14.          scan2 = s2;
  15.          while (*scan1 != '\0' && *scan1 == *scan2) {
  16.                    scan1++;
  17.                    scan2++;
  18.          }
  19.  
  20.          /*
  21.           * The following case analysis is necessary so that characters
  22.           * which look negative collate low against normal characters but
  23.           * high against the end-of-string NUL.
  24.           */
  25.          if (*scan1 == '\0' && *scan2 == '\0')
  26.                    return(0);
  27.          else if (*scan1 == '\0')
  28.                    return(-1);
  29.          else if (*scan2 == '\0')
  30.                    return(1);
  31.          else
  32.                    return(*scan1 - *scan2);
  33. }
  34.