home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Misc / c / strcmpcr < prev    next >
Encoding:
Text File  |  1993-05-15  |  1.5 KB  |  46 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Template.strcmpcr.c
  12.     Author:  Copyright © 1993 Jason Williams
  13.     Version: 1.00 (16 May 1993)
  14.     Purpose: Compare two CR-terminated strings to see if they match
  15. */
  16.  
  17.    /*
  18.     * compares the string pointed to by s1 to the string pointed to by s2.
  19.     * Returns: an integer greater than, equal to, or less than zero, according
  20.     *          as the string pointed to by s1 is greater than, equal to, or
  21.     *          less than the string pointed to by s2.
  22.     */
  23. extern int strcmpcr(char *s1, char *s2)
  24. {
  25.   register int index = 0;
  26.  
  27.   while (s1[index] > 31 && s2[index] > 31)
  28.   {
  29.     if (s1[index] > s2[index])
  30.       return(1);
  31.     else
  32.       if (s1[index] < s2[index])
  33.         return(-1);
  34.       
  35.     index++;
  36.   }
  37.  
  38.   if (s1[index] > 31)        /* s1 is longer than s2, so is greater than */
  39.     return(1);
  40.  
  41.    if (s2[index] > 31)       /* s2 is longer than s1, so result is less than */
  42.     return(-1);
  43.  
  44.   return(0);                 /* Strings exactly match */
  45. }
  46.