home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / strcmp.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  703b  |  39 lines

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