home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / pdc / libsrc / stringlib / strcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-07  |  658 b   |  36 lines

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