home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstrings.arc / STRCMP.C < prev    next >
Encoding:
Text File  |  1985-08-06  |  1.8 KB  |  72 lines

  1. /*
  2.     CSTRINGS.LBR VERSION 1.0
  3.     Spark Software, Inc.
  4.  
  5.         If you find this software of use, it is requested that you send
  6.         a donation ($10.00 suggested) to:
  7.  
  8.             Spark Software, Inc.
  9.             24 Royal Crest Dr., #5
  10.             Nashua, NH  03060
  11.  
  12.         Upon receiving your donation, your name will be added to the 
  13.         List of Registered Users, and future updates can be obtained
  14.         from the SPARKIE RBBS at (603) 888-8179.
  15.  
  16.         If you include an extra $10.00 with your donation, the newest
  17.         version of CSTRINGS.LBR will be mailed to you.
  18.  
  19.         Call SPARKIE RBBS at the number above for other Spark Software
  20.         products!!!
  21. */
  22.  
  23. /*
  24.  *    strcmp (s, t)
  25.  *    char *s, *t;
  26.  *
  27.  *    This function lexicographically compares string s to string t, and
  28.  *    returns an integer equal to 0 if they are identical, less than 0
  29.  *    if s is alphabetically before t, and greater than 0 otherwise.
  30.  */
  31.  
  32. strcmp(s, t)
  33. register char *s, *t;
  34. {
  35.     int i;
  36.  
  37.                     /* Compare s to t keeping track
  38.                        of the first difference */
  39.     while ((i = *s - *t++) == 0 && *s++)
  40.         ;
  41.                     /* Return the difference (if any) */
  42.     return (i);
  43.  
  44. } /* strcmp */
  45.  
  46. /*
  47.  *    strncmp (s, t, len)
  48.  *    char *s, *t;
  49.  *    int len;
  50.  *
  51.  *    This function lexicographically compares string s to string t, and
  52.  *    returns an integer equal to 0 if they are identical, less than 0
  53.  *    if s is alphabetically before t, and greater than 0 otherwise.
  54.  *    At most len characters are compared.
  55.  */
  56.  
  57. strncmp(s, t, len)
  58. register char *s, *t;
  59. register int len;
  60. {
  61.     int i = 0;
  62.  
  63.                     /* Compare s to t keeping track
  64.                        of the first difference */
  65.     while (len-- && (i = *s - *t++) == 0 && *s++)
  66.         ;
  67.  
  68.                     /* Return the difference (if any) */
  69.     return (i);
  70.  
  71. } /* strncmp */
  72.