home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / STRLIB.ZIP / STRNCMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-01-13  |  640 b   |  25 lines

  1.  
  2. /*  File   : strncmp.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 10 April 1984
  5.     Defines: strncmp()
  6.  
  7.     strncmp(s, t, n) compares the first n characters of s and t.
  8.     If they are the same in the first n characters it returns 0,
  9.     otherwise it returns the same value as strcmp(s, t) would.
  10. */
  11.  
  12. #include "strings.h"
  13.  
  14. int strncmp(s, t, n)
  15.     register char *s, *t;
  16.     register int n;
  17.     {
  18.         while (--n >= 0) {
  19.             if (*s != *t++) return s[0]-t[-1];
  20.             if (!*s++) return 0;
  21.         }
  22.         return 0;
  23.      }
  24.  
  25.