home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume5 / smallc / part3 / lib / strncmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  226 b   |  15 lines

  1. /*
  2.  * Compare strings (at most n bytes):  s1>s2: >0  s1==s2: 0  s1<s2: <0
  3.  */
  4.  
  5. strncmp(s1, s2, n)
  6. char *s1, *s2;
  7. int n;
  8. {
  9.  
  10.     while (--n >= 0 && *s1 == *s2++)
  11.         if (*s1++ == '\0')
  12.             return(0);
  13.     return(n<0 ? 0 : *s1 - *--s2);
  14. }
  15.